Skip to content

Conversation

EQUENOS
Copy link
Member

@EQUENOS EQUENOS commented Sep 18, 2023

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
Copy link
Member

@shiftinv shiftinv left a comment

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 👀

@shiftinv
Copy link
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
Copy link
Member Author

EQUENOS commented Sep 23, 2023

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

Comment on lines 837 to +840
for app_command in self.__cog_app_commands__:
if isinstance(app_command, InvokableSlashCommand):
bot.remove_slash_command(app_command.name)
elif isinstance(app_command, InvokableUserCommand):
bot.remove_user_command(app_command.name)
elif isinstance(app_command, InvokableMessageCommand):
bot.remove_message_command(app_command.name)
bot._remove_app_commands(
app_command.body.type, app_command.name, guild_ids=app_command.guild_ids
)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't pose an issue right now, but may need to check for SubCommand(Group) here too.

Copy link

Documentation build overview

📚 disnake | 🛠️ Build #29670169 | 📁 Comparing 311e67e against latest (d473660)


🔍 Preview build

Show files changed (49 files in total): 📝 49 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
index.html 📝 modified
whats_new.html 📝 modified
api/abc.html 📝 modified
api/activities.html 📝 modified
api/app_commands.html 📝 modified
api/app_info.html 📝 modified
api/audit_logs.html 📝 modified
api/automod.html 📝 modified
api/channels.html 📝 modified
api/clients.html 📝 modified
api/components.html 📝 modified
api/emoji.html 📝 modified
api/entitlements.html 📝 modified
api/events.html 📝 modified
api/exceptions.html 📝 modified
api/guild_scheduled_events.html 📝 modified
api/guilds.html 📝 modified
api/integrations.html 📝 modified
api/interactions.html 📝 modified
api/invites.html 📝 modified
api/localization.html 📝 modified
api/members.html 📝 modified
api/messages.html 📝 modified
api/misc.html 📝 modified
api/permissions.html 📝 modified
api/roles.html 📝 modified
api/skus.html 📝 modified
api/soundboard.html 📝 modified
api/stage_instances.html 📝 modified
api/stickers.html 📝 modified
api/subscriptions.html 📝 modified
api/ui.html 📝 modified
api/users.html 📝 modified
api/utilities.html 📝 modified
api/voice.html 📝 modified
api/webhooks.html 📝 modified
api/widgets.html 📝 modified
ext/tasks/index.html 📝 modified
ext/commands/api/app_commands.html 📝 modified
ext/commands/api/bots.html 📝 modified
ext/commands/api/checks.html 📝 modified
ext/commands/api/cogs.html 📝 modified
ext/commands/api/context.html 📝 modified
ext/commands/api/converters.html 📝 modified
ext/commands/api/exceptions.html 📝 modified
ext/commands/api/help_commands.html 📝 modified
ext/commands/api/misc.html 📝 modified
ext/commands/api/prefix_commands.html 📝 modified

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
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