Skip to content

Using cogs with app_commands.command() #8372

Answered by LostLuma
hitblast asked this question in Q&A
Discussion options

You must be logged in to vote

You can create commands inside cogs by simply defining them inside and adding the self argument, similarly to how it works in the commands extension:

@discord.app_commands.command()
async def upload(interaction: discord.Interaction, file: discord.Attachment) -> None:
    ...

class Example(commands.Cog):
    @discord.app_commands.command()
    async def upload(interaction: discord.Interaction, file: discord.Attachment) -> None:
        ....

When the cog is loaded it will be added to the bot's command tree, and you will be able to use and sync it just like all other app commands.

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@hitblast
Comment options

@Soheab
Comment options

@atraboulsi27
Comment options

@LostLuma
Comment options

@atraboulsi27
Comment options

Answer selected by hitblast
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