Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewp-as-is/18c3a8a460c3e4fb41e9b1a7a5b59bad to your computer and use it in GitHub Desktop.
Save andrewp-as-is/18c3a8a460c3e4fb41e9b1a7a5b59bad to your computer and use it in GitHub Desktop.
discord webhook example
<?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>
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