Skip to content
Discussion options

You must be logged in to vote

Slash commands are available under the discord.app_commands namespace. An example command can be made as follows:

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: htt…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@tailoric
Comment options

@Qu1ck1337
Comment options

@tailoric
Comment options

@Qu1ck1337
Comment options

@JDJGInc
Comment options

Answer selected by Qu1ck1337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants