Discord Notify Bot
Receive and send Discord messages, you can combine with other systems to achieve real time notifying.
Python 3.7+
# Web Server
WEB_PORT= Listen port
WEB_USER= Authorized user
WEB_PASSWORD= Authorized password
# Discord Bot
BOT_TOKEN= Discord BotTokenFor applying Discord Bot account, please follow official tutorial
python main.py # Debug mode
python -O main.py # Normal mode
python -O main.py --daemon # Daemon Mode(no interactive shell, suitable for running in backgorund)GET http://{IP:PORT}/get_channels
-
Request method
Request methods/headers Value Method GET Authorization Basic -
Request parameters
None
-
Response
{ "data": { "server": [ "channel 1", "channel 2" ] }, "success": true }
GET http://{IP:PORT}/get_members
-
Request method
Request methods/headers Value Method GET Authorization Basic -
Request parameters
None
-
Response
{ "data": { "server": [ "member 1", "member 2", "member 3" ] }, "success": true }
POST http://{IP:PORT}/send_text
-
Request method
Request methods/headers Value Method POST Authorization Basic Content-Type application/json -
Request parameters
Send to Member
- specify name
{ "user": "member 1", "message": "Hello World" }- specify ID
{ "user": 804285680658284565, "message": "Hello World" }Send to Channel
- specify name
{ "guild": "server", "channel": "channel", "message": "Hello World" }- specify ID
{ "guild": 908285907893895178, "channel": 908285907893895181, "message": "Hello World" } -
Response
{ "data": null, "success": true }
POST http://{IP:PORT}/send_embed
-
Request method
Request methods/headers Value Method POST Authorization Basic Content-Type application/json -
Request parameters
Send to Member
{ "user": "member", "message": { "title": "Title", "description": "Description", "color": "0x3CD10C", "fields": [ {"name": "Line1", "value": "Conten1", "inline": false}, {"name": "Line2", "value": "Conten2", "inline": false}, {"name": "Line3", "value": "Conten3", "inline": false} ] } }Send to Channel
Same as
send_text -
Response
{ "data": null, "success": true }
You can tag users when sending message, only following fields can be recognized
| API | Fields |
|---|---|
| send_text | message |
| send_embed | description, fields.value |
Supported tags
-
@here
"@here Hello World" -
@everyone
"@everyone Hello World" -
@memeber
"<@memeber> Hello World""<@804285680658284565> Hello World"
Followings are Linux shell script, for pure python scripts you can check tests folder
#!/bin/sh
auth_key=user:password
auth_key_encoded=$(echo -n "$auth_key" | base64)
get_url=http://127.0.0.1:5000/get_members
response=$(curl -X GET $get_url -H "Authorization: Basic $auth_key_encoded")
echo $response#!/bin/sh
auth_key=user:password
auth_key_encoded=$(echo -n "$auth_key" | base64)
post_url=http://127.0.0.1:5000/send_text
user=member
msg="Hello World"
curl -X POST $post_url \
-H "Content-Type: application/json" -H "Authorization: Basic $auth_key_encoded" \
-d "{
\"user\": \"$user\",
\"message\":\"$msg\"
}"#!/bin/sh
auth_key=user:password
auth_key_encoded=$(echo -n "$auth_key" | base64)
post_url=http://127.0.0.1:5000/send_embed
user=member
title=Title
description=Desciption
color=0x3CD10C
fields[0]="Line1 Content1"
fields[1]="Line2 Content2"
fields[2]="Line3 Content3"
# use python to generate json
script=$(echo -n "
import json
dic = {}
dic[\"user\"] = \"$user\"
message = {}
dic[\"message\"] = message
message[\"title\"] = \"$title\"
message[\"description\"] = \"$description\"
message[\"color\"] = \"$color\"
fields = []
message[\"fields\"] = fields
$(
for i in "${fields[@]}"
do
values=($i)
echo "fields.append({\"name\":\"${values[0]}\", \"value\":\"${values[1]}\", \"inline\":False})"
done
)
print(json.dumps(dic, ensure_ascii=False, indent=4))
")
content=$(python -c "$script")
curl -X POST $post_url \
-H "Content-Type: application/json" -H "Authorization: Basic $auth_key_encoded" \
-d "$content"
