Last active
October 23, 2025 05:37
-
Star
(125)
You must be signed in to star a gist -
Fork
(21)
You must be signed in to fork a gist
-
-
Save Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2 to your computer and use it in GitHub Desktop.
Simple discord webhook with python
This file contains hidden or 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 # dependency | |
| url = "<your url>" # webhook url, from here: https://i.imgur.com/f9XnAew.png | |
| # for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook | |
| data = { | |
| "content" : "message content", | |
| "username" : "custom username" | |
| } | |
| # leave this out if you dont want an embed | |
| # for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object | |
| data["embeds"] = [ | |
| { | |
| "description" : "text in embed", | |
| "title" : "embed title" | |
| } | |
| ] | |
| result = requests.post(url, json = data) | |
| try: | |
| result.raise_for_status() | |
| except requests.exceptions.HTTPError as err: | |
| print(err) | |
| else: | |
| print(f"Payload delivered successfully, code {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
To attach an image alongside message text, it's important to name the json data
"payload_json"and the image attachment"files[0]", otherwise you will get a 400 error.Doing it this way also allows you to edit the message with requests.patch() without duplicating your attachments.