diff --git a/CHANGELOG.md b/CHANGELOG.md index 911ebd6480..3bf7cd67cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2457](https://github.com/Pycord-Development/pycord/pull/2457)) - Fixed `AttributeError` due to `discord.Option` being initialised with `input_type` set to `None`. ([#2464](https://github.com/Pycord-Development/pycord/pull/2464)) +- Fixed `remove_application_command` causing issues while reloading extensions. + ([#2480](https://github.com/Pycord-Development/pycord/pull/2480)) ### Changed diff --git a/discord/bot.py b/discord/bot.py index 19a1ca9bdc..a81825b494 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -108,7 +108,7 @@ def application_commands(self) -> list[ApplicationCommand]: return list(self._application_commands.values()) def add_application_command(self, command: ApplicationCommand) -> None: - """Adds a :class:`.ApplicationCommand` into the internal list of commands. + """Adds an :class:`.ApplicationCommand` into the internal list of commands. This is usually not called, instead the :meth:`command` or other shortcut decorators are used instead. @@ -143,7 +143,7 @@ def add_application_command(self, command: ApplicationCommand) -> None: def remove_application_command( self, command: ApplicationCommand ) -> ApplicationCommand | None: - """Remove a :class:`.ApplicationCommand` from the internal list + """Remove an :class:`.ApplicationCommand` from the internal list of commands. .. versionadded:: 2.0 @@ -156,16 +156,15 @@ def remove_application_command( Returns ------- Optional[:class:`.ApplicationCommand`] - The command that was removed. If the name is not valid then + The command that was removed. If the command has not been added, ``None`` is returned instead. """ - if command.id is None: - try: - index = self._pending_application_commands.index(command) - except ValueError: - return None - return self._pending_application_commands.pop(index) - return self._application_commands.pop(command.id, None) + if command.id: + self._application_commands.pop(command.id, None) + + if command in self._pending_application_commands: + self._pending_application_commands.remove(command) + return command @property def get_command(self): @@ -185,7 +184,7 @@ def get_application_command( guild_ids: list[int] | None = None, type: type[ApplicationCommand] = ApplicationCommand, ) -> ApplicationCommand | None: - """Get a :class:`.ApplicationCommand` from the internal list + """Get an :class:`.ApplicationCommand` from the internal list of commands. .. versionadded:: 2.0 diff --git a/discord/commands/core.py b/discord/commands/core.py index d89ea0a5b2..3c886f2dfc 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -519,7 +519,7 @@ def before_invoke(self, coro): called. This makes it a useful function to set up database connections or any type of set up required. - This pre-invoke hook takes a sole parameter, a :class:`.ApplicationContext`. + This pre-invoke hook takes a sole parameter, an :class:`.ApplicationContext`. See :meth:`.Bot.before_invoke` for more info. Parameters @@ -544,7 +544,7 @@ def after_invoke(self, coro): called. This makes it a useful function to clean-up database connections or any type of clean up required. - This post-invoke hook takes a sole parameter, a :class:`.ApplicationContext`. + This post-invoke hook takes a sole parameter, an :class:`.ApplicationContext`. See :meth:`.Bot.after_invoke` for more info. Parameters