How can I use slash commands for discord py 2.0? #7764
-
I can't use discord-py-slash-command, because I have some problems with import this library. So, how can I set up slash commands in by bot using discord py 2.0? |
Beta Was this translation helpful? Give feedback.
Answered by
XuaTheGrate
Mar 26, 2022
Replies: 1 comment 10 replies
-
Slash commands are available under the import discord
from discord import app_commands
client = discord.Client(application_id=...) # make sure to specify this ID!
tree = app_commands.CommandTree(client)
@tree.command()
@app_commands.guilds(YOUR_GUILD_ID) # for global commands, don't use this decorator.
async def sample(interaction: discord.Interaction):
await interaction.response.send_message("Hello!")
async def main():
async with client:
await tree.sync(guild=discord.Object(YOUR_GUILD_ID)) # for global commands, omit this parameter
await client.start("YOUR_TOKEN") For further reading: https://discordpy.readthedocs.io/en/master/interactions/api.html |
Beta Was this translation helpful? Give feedback.
10 replies
Answer selected by
Qu1ck1337
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slash commands are available under the
discord.app_commands
namespace. An example command can be made as follows:For further reading: htt…