Skip to content

Commit 109a294

Browse files
authored
fix: remove_application_command missing case (#2480)
* fix: remove_application_command has wrong logic * changelog
1 parent 6bc8309 commit 109a294

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ These changes are available on the `master` branch, but have not yet been releas
7474
([#2457](https://github.com/Pycord-Development/pycord/pull/2457))
7575
- Fixed `AttributeError` due to `discord.Option` being initialised with `input_type` set
7676
to `None`. ([#2464](https://github.com/Pycord-Development/pycord/pull/2464))
77+
- Fixed `remove_application_command` causing issues while reloading extensions.
78+
([#2480](https://github.com/Pycord-Development/pycord/pull/2480))
7779

7880
### Changed
7981

discord/bot.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def application_commands(self) -> list[ApplicationCommand]:
108108
return list(self._application_commands.values())
109109

110110
def add_application_command(self, command: ApplicationCommand) -> None:
111-
"""Adds a :class:`.ApplicationCommand` into the internal list of commands.
111+
"""Adds an :class:`.ApplicationCommand` into the internal list of commands.
112112
113113
This is usually not called, instead the :meth:`command` or
114114
other shortcut decorators are used instead.
@@ -143,7 +143,7 @@ def add_application_command(self, command: ApplicationCommand) -> None:
143143
def remove_application_command(
144144
self, command: ApplicationCommand
145145
) -> ApplicationCommand | None:
146-
"""Remove a :class:`.ApplicationCommand` from the internal list
146+
"""Remove an :class:`.ApplicationCommand` from the internal list
147147
of commands.
148148
149149
.. versionadded:: 2.0
@@ -156,16 +156,15 @@ def remove_application_command(
156156
Returns
157157
-------
158158
Optional[:class:`.ApplicationCommand`]
159-
The command that was removed. If the name is not valid then
159+
The command that was removed. If the command has not been added,
160160
``None`` is returned instead.
161161
"""
162-
if command.id is None:
163-
try:
164-
index = self._pending_application_commands.index(command)
165-
except ValueError:
166-
return None
167-
return self._pending_application_commands.pop(index)
168-
return self._application_commands.pop(command.id, None)
162+
if command.id:
163+
self._application_commands.pop(command.id, None)
164+
165+
if command in self._pending_application_commands:
166+
self._pending_application_commands.remove(command)
167+
return command
169168

170169
@property
171170
def get_command(self):
@@ -185,7 +184,7 @@ def get_application_command(
185184
guild_ids: list[int] | None = None,
186185
type: type[ApplicationCommand] = ApplicationCommand,
187186
) -> ApplicationCommand | None:
188-
"""Get a :class:`.ApplicationCommand` from the internal list
187+
"""Get an :class:`.ApplicationCommand` from the internal list
189188
of commands.
190189
191190
.. versionadded:: 2.0

discord/commands/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def before_invoke(self, coro):
519519
called. This makes it a useful function to set up database
520520
connections or any type of set up required.
521521
522-
This pre-invoke hook takes a sole parameter, a :class:`.ApplicationContext`.
522+
This pre-invoke hook takes a sole parameter, an :class:`.ApplicationContext`.
523523
See :meth:`.Bot.before_invoke` for more info.
524524
525525
Parameters
@@ -544,7 +544,7 @@ def after_invoke(self, coro):
544544
called. This makes it a useful function to clean-up database
545545
connections or any type of clean up required.
546546
547-
This post-invoke hook takes a sole parameter, a :class:`.ApplicationContext`.
547+
This post-invoke hook takes a sole parameter, an :class:`.ApplicationContext`.
548548
See :meth:`.Bot.after_invoke` for more info.
549549
550550
Parameters

0 commit comments

Comments
 (0)