Reputation: 354
I know that recently, discord added the ability for bots to use slash commands. I checked the developer portal and found their resource in the documentation for discord.py. Here is the example they provided:
import requests
url = "https://discord.com/api/v8/applications/<my_application_id>/commands"
json = {
"name": "blep",
"description": "Send a random adorable animal photo",
"options": [
{
"name": "animal",
"description": "The type of animal",
"type": 3,
"required": True,
"choices": [
{
"name": "Dog",
"value": "animal_dog"
},
{
"name": "Cat",
"value": "animal_cat"
},
{
"name": "Penguin",
"value": "animal_penguin"
}
]
},
{
"name": "only_smol",
"description": "Whether to show only baby animals",
"type": 5,
"required": False
}
]
}
# For authorization, you can use either your bot token
headers = {
"Authorization": "Bot 123456"
}
# or a client credentials token for your app with the applications.commands.update scope
headers = {
"Authorization": "Bearer abcdefg"
}
r = requests.post(url, headers=headers, json=json)
What is meant by <my_application_id>? When I tried basically copying and pasting this code for my bot I couldn't get it to work, it kept saying I wasn't authorized. How can I successfully add a slash command to my application, and how can I get a bot to respond to slash command input?
Upvotes: 1
Views: 2924
Reputation: 503
Buttons and Select menus are available in discord.py 2.0, (You need to upgrade to it with this command: pip install -U git+https://github.com/Rapptz/discord.py
)
I would suggest using a module called discord_slash
, it supports Buttons and Dropdowns, unlike a ton of other slash command modules.
Upvotes: 2
Reputation: 155
Take a look at this libary it is easy to use and it works.
https://github.com/eunwoo1104/discord-py-slash-command Have a great day
Upvotes: 0