Skip to content

ApplicationCommandInteraction.slash_command of parent command is overwrited by children command invokations #893

@Snipy7374

Description

@Snipy7374

Summary

This bug is a race condition that concerns parent slash command with attached children commands, found while coding my bot. I noticed this bug defining a after_slash_command_invoke where ApplicationCommandInteraction.application_command.name was returning the same name twice (once for the parent command, once for the subcommand)

Reproduction Steps

  • Create a slash command and attach to it a subcommand
  • Define & set a after_slash_command_invoke callback
  • Enjoy the view

Minimal Reproducible Code

First step: Create a slash command and attach to it a subcommand

@commands.slash_command()
async def packages(self, inter: AppCmdInter):
    return

@packages.sub_command()
async def my_sub_command(self, inter: AppCmdInter):
    ...

Second step: Define & set a after_slash_command_invoke callback

@bot.after_slash_command_invoke
async def my_after_invoke(inter: AppCmdInter):
    print(inter.application_command.name)

or subclassing commands.Bot

class MyBot(commands.Bot):
    def __init__(self):
        ...
        self._after_slash_command_invoke = self.my_after_invoke

    async def my_after_invoke(self, inter: AppCmdInter):
        print(inter.application_command.name)

demo of the output:

2022-12-10 17:47:21.890 | INFO     | _logging:log_message:43 - :SnipyBot.my_after_slash_command_invoke: - Snipy#7374 - 710570210159099984 | CodeWithVincent - 920882891024629790 | Command search was executed in 0.616953s
2022-12-10 17:47:22.928 | INFO     | _logging:log_message:43 - :SnipyBot.my_after_slash_command_invoke: - Snipy#7374 - 710570210159099984 | CodeWithVincent - 920882891024629790 | Command search was executed in 1.654488s

Expected Results

The after_slash_command_invoke is called once (just for the sub_command) or at least the ApplicationCommandInteraction.application_command doesn't get overwrited

Actual Results

after_slash_command_invoke is called twice (once for the parent command and once for it's sub_command) and the ApplicationCommandInteraction.application_command is overwritten

Intents

disnake.Intents.default()

System Information

irrelevants

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions