'Discord clicking button using api and requests in python not working
I have made this code to make a user interact with a button of my bot’s message, but i am unable to make it work. Please help.I get the following error:
{"code": 50035, "errors": {"session_id": {"_errors": [{"code": "BASE_TYPE_REQUIRED", "message": "This field is required"}]}}, "message": "Invalid Form Body”}
header = {
'authorization': auth
}
r = requests.get("https://discord.com/api/v9/channels/<channel_id>/messages", headers = header)
message = json.loads(r.text)[0]
data = {
"type": 3,
"guild_id": '<guild_id>',
"channel_id": '<channel_id>',
"message_id": message['id'],
"application_id": '<bot_id>', #the id of the bot to which i want to interact
"data": {
"component_type": 2,
"custom_id": message['components'][0]['components'][2]['custom_id'] #gets the custom_id of the button to interact
}
}
r = requests.post('https://discord.com/api/v9/interactions', json = data, headers = header)
Solution 1:[1]
Turns out, I need to add a session_id under the data dict, the problem got solved! Thanks furas for your help!
The code now:
data = {
"type": 3,
"guild_id": '<guild_id>',
"channel_id": '<channel_id>',
"message_id": message['id'],
"session_id": '<session_id>', #if you don't know the string, a random string worked for me
"application_id": '<bot_id>', #the id of the bot to which i want to interact
"data": {
"component_type": 2,
"custom_id": message['components'][0]['components'][2]['custom_id'] #gets the custom_id of the button to interact
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jayahemanth P |
