Created
April 14, 2024 23:14
-
-
Save jgs03177/ad6e316e94aac84c4e878bc25b8b091b to your computer and use it in GitHub Desktop.
discord send message/file via webhook
This file contains 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
# https://gist.github.com/Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2 | |
# https://www.reddit.com/r/Discord_Bots/comments/iirmzy/how_to_send_files_using_discord_webhooks_python/ | |
import requests | |
webhook_url = "Insert Webhook URL" # discord webhook url | |
# test? | |
# result = requests.get(webhook_url) | |
# send message | |
data = { | |
"content" : "Insert Any Message", | |
"username" : "Insert Any Name", | |
} | |
result = requests.post(webhook_url, json = data) | |
# or send file | |
filepath = "Insert FILE PATH" | |
result = requests.post(webhook_url, files={"file": open(filepath, 'rb')}) | |
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