Last active
July 20, 2019 15:07
-
-
Save andrewp-as-is/18c3a8a460c3e4fb41e9b1a7a5b59bad to your computer and use it in GitHub Desktop.
discord webhook example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>URL</key> | |
<string>https://discordapp.com/developers/docs/resources/webhook#execute-webhook</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import os | |
# prevent 400 ERROR | |
DESCRIPTION_MAX_LENGTH = 1900 | |
TITLE_MAX_LENGTH = 255 | |
TIMEOUT = 5 | |
URL = os.environ["LOGS_WEBHOOK_URL"] | |
data = {} | |
# for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook | |
data["content"] = "message content" | |
# data["username"] = "custom username" | |
# leave this out if you dont want an embed | |
data["embeds"] = [] | |
embed = {} | |
# for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object | |
embed["description"] = "text in embed"[0:DESCRIPTION_MAX_LENGTH] | |
embed["title"] = "embed title"[0:TITLE_MAX_LENGTH] | |
data["embeds"].append(embed) | |
result = requests.post(URL, data=json.dumps(data), headers={"Content-Type": "application/json"}) | |
try: | |
result.raise_for_status() | |
except requests.exceptions.HTTPError as err: | |
print(err) | |
else: | |
print("Payload delivered successfully, code {}.".format(result.status_code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment