Skip to content

Instantly share code, notes, and snippets.

@a4amaan
Forked from Bilka2/webhook.py
Created September 11, 2020 11:08
Show Gist options
  • Save a4amaan/045da01232a0718a1276b60d8edb0f17 to your computer and use it in GitHub Desktop.
Save a4amaan/045da01232a0718a1276b60d8edb0f17 to your computer and use it in GitHub Desktop.
Simple discord webhook with python
import requests #dependency
import json
url = "<your url>" #webhook url, from here: https://i.imgur.com/aT3AThK.png
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"
embed["title"] = "embed title"
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))
#result: https://i.imgur.com/DRqXQzA.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment