How do I send a message on discord channel from python? I tried YouTube videos they aren't working also I want the messages to be timed like after every 1 minute the message should go
import requests
token = '(my_token)'
channel_id = '(my_channel_id)'
message = 'thanks'
def sendmessage(token, channel_id, message):
url = 'https://discord.com/api/v9/channels/{}/messages'.format(channel_id)
data = {
'content': message
}
header = {'authorisation': token}
r = requests.post(url, data=data, headers=header)
sendmessage(token, channel_id, message)
You have typo - it should be
zinauthorization.Your code works for me if I run discord in browser and copy my private token from browser
but it doesn't work with my bot token.
For bot it needs:
Eventually it may need also
User-Agentwith bot's name (but I'm not sure if it is really required) .Found in: sends messages to a discord channel using a bot via http POST