Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
3 tasks done
Snipy7374 opened this issue Dec 10, 2022 · 0 comments · May be fixed by #1192
Open
3 tasks done
Labels
bug Something isn't working

Comments

@Snipy7374
Copy link
Collaborator

Snipy7374 commented Dec 10, 2022

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

@Snipy7374 Snipy7374 added the unconfirmed bug Something might not be working label Dec 10, 2022
@Snipy7374 Snipy7374 changed the title The ApplicationCommandInteraction.slash_command of a parent command is overwrited by children command invokations ApplicationCommandInteraction.slash_command of a parent command is overwrited by children command invokations Dec 10, 2022
@Snipy7374 Snipy7374 changed the title ApplicationCommandInteraction.slash_command of a parent command is overwrited by children command invokations ApplicationCommandInteraction.slash_command of parent command is overwrited by children command invokations Dec 10, 2022
@shiftinv shiftinv added bug Something isn't working and removed unconfirmed bug Something might not be working labels Dec 11, 2022
@shiftinv shiftinv added the 3.0 label May 15, 2024
@KnownBlackHat KnownBlackHat linked a pull request May 15, 2024 that will close this issue
8 tasks
@shiftinv shiftinv removed the 3.0 label May 15, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants