Trigger a Slash Command using Requests

93 views Asked by At

I tried triggering a Slash Command using requests, but I have came around an error I have no clue how to fix.

Code:


import requests

payload = {

"type": 2,

"application_id": "999736048596816014",

"guild_id": "1190781950944886867",

"channel_id": "1190781950944886870",

"session_id": "4d8f14035632b07e98830b5a9706e1d6",

"data": {

"version": "1171521015759769721",

"id": "1001775070169022494",

"name": "about",

"application_command": {

"id": "1001775070169022494",

"application_id": "999736048596816014",

},

},

}

headers = {

"Authorization": "my token here",

"content-type": "application/json"

}

r = requests.post("https://discord.com/api/v9/interactions", json=payload, headers=headers)

print(r.text)

Error:


{"message": "Invalid Form Body", "code": 50035, "errors": {"data": {"_errors": [{"code": "INTERACTION_APPLICATION_COMMAND_INVALID", "message": "Invalid interaction application command"}]}}}

I tried using a full payload copied from the Networking Tab on the Developer Console, but I was still getting the same error.

If anyone could help me It would mean a lot to me. Thanks in advance!

1

There are 1 answers

3
M Junaid On
import requests
import json

payload = {
        "type": 2,
        "token": "your_bot_token_here",
        "guild_id": "your_guild_id_here",
        "channel_id": "your_channel_id_here",
         "data": {
         "name": "your_command_name_here",
         "options": []  # If your command has options, provide them here
         }
       }

  headers = {
    "Content-Type": "application/json"
    }

   response = requests.post("https://discord.com/api/v9/interactions", 
   data=json.dumps(payload), headers=headers)
   print(response.json())