Skip to content

refactor(commands): rewrite app command storage to support multiple per-guild commands with the same name - #1107

Open
EQUENOS wants to merge 70 commits into
masterfrom
refactor/app-command-storage
Open

refactor(commands): rewrite app command storage to support multiple per-guild commands with the same name#1107
EQUENOS wants to merge 70 commits into
masterfrom
refactor/app-command-storage

Conversation

@EQUENOS

@EQUENOS EQUENOS commented Sep 18, 2023

Copy link
Copy Markdown
Member

Summary

Currently, disnake.ext.commands framework doesn't allow registering 2 guild commands with the same type and name in different guilds, even though discord API allows to do that (see issue #260). This PR solves this problem.

Consequences

  • all_xxx_commands attributes of InteractionBotBase are now deprecated in favor of all_app_commands
  • bot.add_xxx_command methods are now deprecated in favor of add_app_command
  • bot.remove_xxx_command methods are now deprecated in favor of remove_app_command
  • bot.get_xxx_command now works in O(1) only if guild_id is specified, otherwise it's O(n) where n = len(all_app_commands)
  • bot.get_xxx_command can be ambiguous if guild_id is not specified
  • argument guild_id of bot._ordered_unsynced_commands is now deprecated

Note

The original idea of allowing to insert IDs of app commands to the corresponding invokable objects had to be abandoned. This is due to complications related to copying.

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running pdm lint
    • I have type-checked the code by running pdm pyright
  • This PR fixes an issue
  • This PR adds something new (e.g. new method or parameters)
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@EQUENOS EQUENOS added p: medium Medium priority t: refactor/typing/lint Refactors, typing changes and/or linting changes s: in progress Issue/PR is being worked on labels Sep 18, 2023
@EQUENOS EQUENOS changed the title refactor: Store invokable application commands properly refactor: store invokable application commands properly Sep 18, 2023
@EQUENOS EQUENOS added s: needs review Issue/PR is awaiting reviews t: deprecation Deprecation of existing features t: bugfix and removed s: in progress Issue/PR is being worked on labels Sep 18, 2023
Comment thread disnake/interactions/application_command.py
Comment thread disnake/ext/commands/interaction_bot_base.py
Comment thread disnake/ext/commands/interaction_bot_base.py Outdated
Comment thread disnake/ext/commands/interaction_bot_base.py Outdated

@shiftinv shiftinv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a bunch of mostly minor comments, but overall this looks really cool 👀

Comment thread changelog/260.deprecate.0.rst Outdated
Comment thread changelog/260.deprecate.0.rst Outdated
Comment thread disnake/ext/commands/errors.py
Comment thread disnake/ext/commands/errors.py Outdated
Comment thread disnake/ext/commands/interaction_bot_base.py Outdated
Comment thread disnake/ext/commands/interaction_bot_base.py Outdated
Comment thread disnake/ext/commands/interaction_bot_base.py Outdated
Comment thread disnake/ext/commands/interaction_bot_base.py
Comment thread docs/ext/commands/api/exceptions.rst Outdated
Comment thread disnake/interactions/application_command.py Outdated
@shiftinv

Copy link
Copy Markdown
Member

Haven't tested much yet - not sure what exactly happened, but something somewhere ended up trying to register subcommands as top-level commands: https://gist.github.com/shiftinv/eddfcae9ca1f34790ced4a5288e3691f

@EQUENOS

EQUENOS commented Sep 23, 2023

Copy link
Copy Markdown
Member Author

Haven't tested much yet - not sure what exactly happened, but something somewhere ended up trying to register subcommands as top-level commands: https://gist.github.com/shiftinv/eddfcae9ca1f34790ced4a5288e3691f

Fixed this in 1f10a8d

@read-the-docs-community

read-the-docs-community Bot commented Sep 21, 2025

Copy link
Copy Markdown

Documentation build overview

📚 disnake | 🛠️ Build #34170119 | 📁 Comparing 35455ee against latest (c85e0b4)

  🔍 Preview build  

49 files changed · ± 49 modified

± Modified

@shiftinv shiftinv changed the title refactor: store invokable application commands properly refactor(commands): rewrite app command storage to support multiple per-guild commands with the same name Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: medium Medium priority s: needs review Issue/PR is awaiting reviews t: bugfix t: deprecation Deprecation of existing features t: refactor/typing/lint Refactors, typing changes and/or linting changes

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Separate application commands with same name+type but in different guilds don't work

5 participants