Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: remove_application_command missing case #2480

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 10 additions & 11 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading