-
-
Save Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2 to your computer and use it in GitHub Desktop.
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 |
Is there a way to attach embed images?
Hey guys, is there a way to send texts that are actually links?
like in html e.g(Text)
I am trying to send shoe sizes as a message to my chanel, and I want to be able to click on those sizes and itll take me to the respective page of each size
@andyias you can use markdown links in the webhook content
[the link](https://example.com)
this is something unique to webhooks, and won't work for normal discord messages.
@Senoel i recommend taking a look at https://leovoel.github.io/embed-visualizer/ (make sure to click on "webhook mode")
you can also take a look at https://birdie0.github.io/discord-webhooks-guide/structure/file.html for sending files without an embed
very useful
very useful, since im a noob with python :D
Neat, thanks!
how would one attach a file?
do we just use .read() for the contents? and where does the file name go?
how would one attach a file? do we just use .read() for the contents? and where does the file name go?
@Hypurrnating I think you can use this:
requests.post("<your webhook url>", json = {"content": "<your message here (you can just set to an empty string)>"}, files = {"myfile": open("<your file path here>", "rb")})
Note that you can change myfile
to anything other, and so, add multiple items into the dictionnary passed to files
by changing the name.
My desire to support pre-3.6 is a good enough reason to keep the code how it is.