Skip to content

Instantly share code, notes, and snippets.

@Bilka2
Last active May 12, 2024 07:17
Show Gist options
  • Save Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2 to your computer and use it in GitHub Desktop.
Save Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2 to your computer and use it in GitHub Desktop.
Simple discord webhook with python
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
@15u43i
Copy link

15u43i commented Apr 27, 2022

Neat, thanks!

@Hypurrnating
Copy link

how would one attach a file?
do we just use .read() for the contents? and where does the file name go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment