Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranoke/2a0d2f2dbf1e0c551795a07657a91cd9 to your computer and use it in GitHub Desktop.
Save ranoke/2a0d2f2dbf1e0c551795a07657a91cd9 to your computer and use it in GitHub Desktop.
sends messages to a discord channel using a bot via http POST
# post a message to discord api via a bot
# bot must be added to the server and have write access to the channel
# you may need to connect with a websocket the first time you run the bot
# use a library like discord.py to do so
import requests
import json
channelID = "your_id_goes_here" # enable dev mode on discord, right-click on the channel, copy ID
botToken = "your_token_here" # get from the bot page. must be a bot, not a discord app
baseURL = "https://discordapp.com/api/channels/{}/messages".format(channelID)
headers = { "Authorization":"Bot {}".format(botToken),
"User-Agent":"myBotThing (http://some.url, v0.1)",
"Content-Type":"application/json", }
message = "hello world"
POSTedJSON = json.dumps ( {"content":message} )
r = requests.post(baseURL, headers = headers, data = POSTedJSON)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment