From 235e4bc74bb29a9993d44105a0faa35feaff5d2e Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Sat, 21 Feb 2026 22:14:28 +0100 Subject: [PATCH 1/8] Add kwargs explicitly for app-command decorators --- CHANGELOG.md | 3 + discord/bot.py | 141 ++++++++++++++++++++++++++++++++++-- discord/commands/core.py | 149 +++++++++++++++++++++++++++++++++++---- 3 files changed, 271 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b44909cf7..00cdf35b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#3105](https://github.com/Pycord-Development/pycord/pull/3105)) - Fixed the update of a user's `avatar_decoration` to now cause an `on_user_update` event to fire. ([#3103](https://github.com/Pycord-Development/pycord/pull/3103)) +- Fixed the `discord.slash_command` and `ApplicationContext.respond` methods to + explicitly list the accepted parameters, and have a return type. + ([#3119](https://github.com/Pycord-Development/pycord/pull/3119)) ### Deprecated diff --git a/discord/bot.py b/discord/bot.py index 5ba5f9b5df..d97d738ac8 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -66,7 +66,11 @@ from .utils import MISSING, async_all, find, get if TYPE_CHECKING: + from .cog import Cog + from .commands import Option + from .ext.commands import Cooldown from .member import Member + from .permissions import Permissions C = TypeVar("C", bound=MessageCommand | SlashCommand | UserCommand) CoroFunc = Callable[..., Coroutine[Any, Any, Any]] @@ -909,7 +913,24 @@ async def callback() -> None: if not autocomplete_task.done(): autocomplete_task.cancel() - def slash_command(self, **kwargs): + def slash_command( + self, + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + description: str | None = MISSING, + description_localizations: dict[str, str] | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + options: list[Option] | None = MISSING, + parent: SlashCommandGroup | None = MISSING, + **kwargs: Any, + ) -> Callable[[...], SlashCommand]: """A shortcut decorator for adding a slash command to the bot. This is equivalent to using :meth:`application_command`, providing the :class:`SlashCommand` class. @@ -922,9 +943,39 @@ def slash_command(self, **kwargs): A decorator that converts the provided function into a :class:`.SlashCommand`, adds it to the bot, and returns it. """ - return self.application_command(cls=SlashCommand, **kwargs) + return self.application_command( + cls=SlashCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + description=description, + description_localizations=description_localizations, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + options=options, + parent=parent, + **kwargs, + ) - def user_command(self, **kwargs): + def user_command( + self, + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + **kwargs: Any, + ) -> Callable[..., UserCommand]: """A shortcut decorator for adding a user command to the bot. This is equivalent to using :meth:`application_command`, providing the :class:`UserCommand` class. @@ -937,9 +988,35 @@ def user_command(self, **kwargs): A decorator that converts the provided function into a :class:`.UserCommand`, adds it to the bot, and returns it. """ - return self.application_command(cls=UserCommand, **kwargs) + return self.application_command( + cls=UserCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + **kwargs, + ) - def message_command(self, **kwargs): + def message_command( + self, + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + **kwargs: Any, + ) -> Callable[..., MessageCommand]: """A shortcut decorator for adding a message command to the bot. This is equivalent to using :meth:`application_command`, providing the :class:`MessageCommand` class. @@ -952,9 +1029,40 @@ def message_command(self, **kwargs): A decorator that converts the provided function into a :class:`.MessageCommand`, adds it to the bot, and returns it. """ - return self.application_command(cls=MessageCommand, **kwargs) + return self.application_command( + cls=MessageCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + **kwargs, + ) - def application_command(self, cls: type[C] = SlashCommand, **kwargs): + def application_command( + self, + cls: type[C] = SlashCommand, + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + description: str | None = MISSING, + description_localizations: dict[str, str] | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + options: list[Option] | None = MISSING, + parent: SlashCommandGroup | None = MISSING, + **kwargs: Any, + ) -> Callable[..., C]: """A shortcut decorator that converts the provided function into an application command via :func:`command` and adds it to the internal command list via :meth:`~.Bot.add_application_command`. @@ -976,6 +1084,25 @@ class be provided, it must be a subclass of either adds it to the bot, and returns it. """ + params = { + "checks": checks, + "cog": cog, + "contexts": contexts, + "cooldown": cooldown, + "default_member_permissions": default_member_permissions, + "description": description, + "description_localizations": description_localizations, + "guild_ids": guild_ids, + "integration_types": integration_types, + "name": name, + "name_localizations": name_localizations, + "nsfw": nsfw, + "options": options, + "parent": parent, + **kwargs, + } + kwargs = {k: v for k, v in params.items() if v is not MISSING} + def decorator(func) -> C: result = command(cls=cls, **kwargs)(func) self.add_application_command(result) diff --git a/discord/commands/core.py b/discord/commands/core.py index 1953561365..a0ed5566bb 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -93,8 +93,9 @@ from typing_extensions import Concatenate, ParamSpec from .. import Permissions + from ..bot import C from ..cog import Cog - from ..ext.commands.cooldowns import CooldownMapping, MaxConcurrency + from ..ext.commands.cooldowns import Cooldown, CooldownMapping, MaxConcurrency T = TypeVar("T") CogT = TypeVar("CogT", bound="Cog") @@ -1978,7 +1979,23 @@ def _update_copy(self, kwargs: dict[str, Any]): return self.copy() -def slash_command(**kwargs): +def slash_command( + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + description: str | None = MISSING, + description_localizations: dict[str, str] | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + options: list[Option] | None = MISSING, + parent: SlashCommandGroup | None = MISSING, + **kwargs: Any, +) -> Callable[[...], SlashCommand]: """Decorator for slash commands that invokes :func:`application_command`. .. versionadded:: 2.0 @@ -1988,10 +2005,39 @@ def slash_command(**kwargs): Callable[..., :class:`.SlashCommand`] A decorator that converts the provided method into a :class:`.SlashCommand`. """ - return application_command(cls=SlashCommand, **kwargs) - - -def user_command(**kwargs): + return application_command( + cls=SlashCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + description=description, + description_localizations=description_localizations, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + options=options, + parent=parent, + **kwargs, + ) + + +def user_command( + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + **kwargs: Any, +) -> Callable[..., UserCommand]: """Decorator for user commands that invokes :func:`application_command`. .. versionadded:: 2.0 @@ -2001,10 +2047,35 @@ def user_command(**kwargs): Callable[..., :class:`.UserCommand`] A decorator that converts the provided method into a :class:`.UserCommand`. """ - return application_command(cls=UserCommand, **kwargs) - - -def message_command(**kwargs): + return application_command( + cls=UserCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + **kwargs, + ) + + +def message_command( + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + **kwargs: Any, +) -> Callable[..., MessageCommand]: """Decorator for message commands that invokes :func:`application_command`. .. versionadded:: 2.0 @@ -2014,10 +2085,40 @@ def message_command(**kwargs): Callable[..., :class:`.MessageCommand`] A decorator that converts the provided method into a :class:`.MessageCommand`. """ - return application_command(cls=MessageCommand, **kwargs) - - -def application_command(cls=SlashCommand, **attrs): + return application_command( + cls=MessageCommand, + checks=checks, + cog=cog, + contexts=contexts, + cooldown=cooldown, + default_member_permissions=default_member_permissions, + guild_ids=guild_ids, + integration_types=integration_types, + name=name, + name_localizations=name_localizations, + nsfw=nsfw, + **kwargs, + ) + + +def application_command( + cls=SlashCommand, + checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, + cog: Cog | None = MISSING, + contexts: set[InteractionContextType] | None = MISSING, + cooldown: Cooldown | None = MISSING, + default_member_permissions: Permissions | None = MISSING, + description: str | None = MISSING, + description_localizations: dict[str, str] | None = MISSING, + guild_ids: list[int] | None = MISSING, + integration_types: set[IntegrationType] | None = MISSING, + name: str | None = MISSING, + name_localizations: dict[str, str] | None = MISSING, + nsfw: bool = False, + options: list[Option] | None = MISSING, + parent: SlashCommandGroup | None = MISSING, + **kwargs: Any, +) -> Callable[..., C]: """A decorator that transforms a function into an :class:`.ApplicationCommand`. More specifically, usually one of :class:`.SlashCommand`, :class:`.UserCommand`, or :class:`.MessageCommand`. The exact class depends on the ``cls`` parameter. @@ -2048,6 +2149,24 @@ def application_command(cls=SlashCommand, **attrs): TypeError If the function is not a coroutine or is already a command. """ + params = { + "checks": checks, + "cog": cog, + "contexts": contexts, + "cooldown": cooldown, + "default_member_permissions": default_member_permissions, + "description": description, + "description_localizations": description_localizations, + "guild_ids": guild_ids, + "integration_types": integration_types, + "name": name, + "name_localizations": name_localizations, + "nsfw": nsfw, + "options": options, + "parent": parent, + **kwargs, + } + kwargs = {k: v for k, v in params.items() if v is not MISSING} def decorator(func: Callable) -> cls: if isinstance(func, ApplicationCommand): @@ -2056,7 +2175,7 @@ def decorator(func: Callable) -> cls: raise TypeError( "func needs to be a callable or a subclass of ApplicationCommand." ) - return cls(func, **attrs) + return cls(func, **kwargs) return decorator From aaf13a299acdec3bd284baef17933e8f7faf4cf1 Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Sat, 28 Feb 2026 20:38:38 +0100 Subject: [PATCH 2/8] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1535f6ceb..b5897cb3b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#3105](https://github.com/Pycord-Development/pycord/pull/3105)) - Fixed the update of a user's `avatar_decoration` to now cause an `on_user_update` event to fire. ([#3103](https://github.com/Pycord-Development/pycord/pull/3103)) -- Fixed the `discord.slash_command` and `ApplicationContext.respond` methods to +- Fixed the `slash_command`, `message_command` and `user_command` decorators to explicitly list the accepted parameters, and have a return type. ([#3119](https://github.com/Pycord-Development/pycord/pull/3119)) From dc45c8c73e72567348528b664e35a8050c5f74f0 Mon Sep 17 00:00:00 2001 From: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Date: Mon, 9 Mar 2026 16:09:56 +0100 Subject: [PATCH 3/8] Remove changelog entry Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5897cb3b3..62d9b0b949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,6 @@ These changes are available on the `master` branch, but have not yet been releas ([#3105](https://github.com/Pycord-Development/pycord/pull/3105)) - Fixed the update of a user's `avatar_decoration` to now cause an `on_user_update` event to fire. ([#3103](https://github.com/Pycord-Development/pycord/pull/3103)) -- Fixed the `slash_command`, `message_command` and `user_command` decorators to - explicitly list the accepted parameters, and have a return type. - ([#3119](https://github.com/Pycord-Development/pycord/pull/3119)) ### Deprecated From 8e6089b872115737de77847608ac197ba83eb664 Mon Sep 17 00:00:00 2001 From: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Date: Wed, 18 Mar 2026 22:48:41 +0100 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: plun1331 Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> --- discord/bot.py | 4 ++++ discord/commands/core.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/discord/bot.py b/discord/bot.py index d97d738ac8..957bfbfb77 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -915,6 +915,7 @@ async def callback() -> None: def slash_command( self, + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -964,6 +965,7 @@ def slash_command( def user_command( self, + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -1005,6 +1007,7 @@ def user_command( def message_command( self, + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -1046,6 +1049,7 @@ def message_command( def application_command( self, + *, cls: type[C] = SlashCommand, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, diff --git a/discord/commands/core.py b/discord/commands/core.py index a0ed5566bb..6714065798 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1980,6 +1980,7 @@ def _update_copy(self, kwargs: dict[str, Any]): def slash_command( + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -2026,6 +2027,7 @@ def slash_command( def user_command( + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -2064,6 +2066,7 @@ def user_command( def message_command( + *, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -2102,6 +2105,7 @@ def message_command( def application_command( + *, cls=SlashCommand, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, From 58ca91dfb034edabe1d40ba4c2b35746f9c961ab Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Thu, 9 Apr 2026 17:16:50 +0200 Subject: [PATCH 5/8] Update kwarg typing to be `Never` to discourage random kwarg passing --- discord/bot.py | 10 ++++++---- discord/commands/core.py | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/discord/bot.py b/discord/bot.py index 957bfbfb77..5285202a67 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -66,6 +66,8 @@ from .utils import MISSING, async_all, find, get if TYPE_CHECKING: + from typing_extensions import Never + from .cog import Cog from .commands import Option from .ext.commands import Cooldown @@ -930,7 +932,7 @@ def slash_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Any, + **kwargs: Never, ) -> Callable[[...], SlashCommand]: """A shortcut decorator for adding a slash command to the bot. This is equivalent to using :meth:`application_command`, providing @@ -976,7 +978,7 @@ def user_command( name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, nsfw: bool = False, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., UserCommand]: """A shortcut decorator for adding a user command to the bot. This is equivalent to using :meth:`application_command`, providing @@ -1018,7 +1020,7 @@ def message_command( name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, nsfw: bool = False, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., MessageCommand]: """A shortcut decorator for adding a message command to the bot. This is equivalent to using :meth:`application_command`, providing @@ -1065,7 +1067,7 @@ def application_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., C]: """A shortcut decorator that converts the provided function into an application command via :func:`command` and adds it to diff --git a/discord/commands/core.py b/discord/commands/core.py index 556e5de78a..7529cd2d72 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -90,7 +90,7 @@ ) if TYPE_CHECKING: - from typing_extensions import Concatenate, ParamSpec + from typing_extensions import Concatenate, Never, ParamSpec from .. import Permissions from ..bot import C @@ -1995,7 +1995,7 @@ def slash_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Any, + **kwargs: Never, ) -> Callable[[...], SlashCommand]: """Decorator for slash commands that invokes :func:`application_command`. @@ -2038,7 +2038,7 @@ def user_command( name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, nsfw: bool = False, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., UserCommand]: """Decorator for user commands that invokes :func:`application_command`. @@ -2077,7 +2077,7 @@ def message_command( name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, nsfw: bool = False, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., MessageCommand]: """Decorator for message commands that invokes :func:`application_command`. @@ -2121,7 +2121,7 @@ def application_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Any, + **kwargs: Never, ) -> Callable[..., C]: """A decorator that transforms a function into an :class:`.ApplicationCommand`. More specifically, usually one of :class:`.SlashCommand`, :class:`.UserCommand`, or :class:`.MessageCommand`. The exact class From d11726ff13064ab2c08cdff7e0e33436de16b3ee Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Thu, 9 Apr 2026 17:55:30 +0200 Subject: [PATCH 6/8] Add deprecated guild_only kwarg to signature --- discord/bot.py | 8 ++++++++ discord/commands/core.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/discord/bot.py b/discord/bot.py index 5285202a67..27e17647ee 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -926,6 +926,7 @@ def slash_command( description: str | None = MISSING, description_localizations: dict[str, str] | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -956,6 +957,7 @@ def slash_command( description=description, description_localizations=description_localizations, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -974,6 +976,7 @@ def user_command( cooldown: Cooldown | None = MISSING, default_member_permissions: Permissions | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -1000,6 +1003,7 @@ def user_command( cooldown=cooldown, default_member_permissions=default_member_permissions, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -1016,6 +1020,7 @@ def message_command( cooldown: Cooldown | None = MISSING, default_member_permissions: Permissions | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -1042,6 +1047,7 @@ def message_command( cooldown=cooldown, default_member_permissions=default_member_permissions, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -1061,6 +1067,7 @@ def application_command( description: str | None = MISSING, description_localizations: dict[str, str] | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -1099,6 +1106,7 @@ class be provided, it must be a subclass of either "description": description, "description_localizations": description_localizations, "guild_ids": guild_ids, + "guild_only": guild_only, "integration_types": integration_types, "name": name, "name_localizations": name_localizations, diff --git a/discord/commands/core.py b/discord/commands/core.py index 7529cd2d72..0ae6e2b7ff 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1989,6 +1989,7 @@ def slash_command( description: str | None = MISSING, description_localizations: dict[str, str] | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -2016,6 +2017,7 @@ def slash_command( description=description, description_localizations=description_localizations, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -2034,6 +2036,7 @@ def user_command( cooldown: Cooldown | None = MISSING, default_member_permissions: Permissions | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -2057,6 +2060,7 @@ def user_command( cooldown=cooldown, default_member_permissions=default_member_permissions, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -2073,6 +2077,7 @@ def message_command( cooldown: Cooldown | None = MISSING, default_member_permissions: Permissions | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -2096,6 +2101,7 @@ def message_command( cooldown=cooldown, default_member_permissions=default_member_permissions, guild_ids=guild_ids, + guild_only=guild_only, integration_types=integration_types, name=name, name_localizations=name_localizations, @@ -2115,6 +2121,7 @@ def application_command( description: str | None = MISSING, description_localizations: dict[str, str] | None = MISSING, guild_ids: list[int] | None = MISSING, + guild_only: bool | None = MISSING, integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, @@ -2162,6 +2169,7 @@ def application_command( "description": description, "description_localizations": description_localizations, "guild_ids": guild_ids, + "guild_only": guild_only, "integration_types": integration_types, "name": name, "name_localizations": name_localizations, From c9766b4c9425cb674c193b709933d68449a685d8 Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Sun, 12 Apr 2026 16:29:57 +0200 Subject: [PATCH 7/8] Change kwargs back to Any for application_command decorators --- discord/bot.py | 2 +- discord/commands/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/bot.py b/discord/bot.py index 27e17647ee..6dccf83b01 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -1074,7 +1074,7 @@ def application_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Never, + **kwargs: Any, ) -> Callable[..., C]: """A shortcut decorator that converts the provided function into an application command via :func:`command` and adds it to diff --git a/discord/commands/core.py b/discord/commands/core.py index 0ae6e2b7ff..ecc05753e5 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -2128,7 +2128,7 @@ def application_command( nsfw: bool = False, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, - **kwargs: Never, + **kwargs: Any, ) -> Callable[..., C]: """A decorator that transforms a function into an :class:`.ApplicationCommand`. More specifically, usually one of :class:`.SlashCommand`, :class:`.UserCommand`, or :class:`.MessageCommand`. The exact class From 97deb6703ea1ec1fb3a91b11dfc90d974019e448 Mon Sep 17 00:00:00 2001 From: ToothyDev Date: Mon, 13 Apr 2026 17:30:49 +0200 Subject: [PATCH 8/8] Apply code review change requests --- discord/bot.py | 10 +++++----- discord/commands/core.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/discord/bot.py b/discord/bot.py index 6dccf83b01..2268568496 100644 --- a/discord/bot.py +++ b/discord/bot.py @@ -930,11 +930,11 @@ def slash_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, **kwargs: Never, - ) -> Callable[[...], SlashCommand]: + ) -> Callable[..., SlashCommand]: """A shortcut decorator for adding a slash command to the bot. This is equivalent to using :meth:`application_command`, providing the :class:`SlashCommand` class. @@ -980,7 +980,7 @@ def user_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, **kwargs: Never, ) -> Callable[..., UserCommand]: """A shortcut decorator for adding a user command to the bot. @@ -1024,7 +1024,7 @@ def message_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, **kwargs: Never, ) -> Callable[..., MessageCommand]: """A shortcut decorator for adding a message command to the bot. @@ -1071,7 +1071,7 @@ def application_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, **kwargs: Any, diff --git a/discord/commands/core.py b/discord/commands/core.py index ecc05753e5..d2f8f52f69 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1993,11 +1993,11 @@ def slash_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, **kwargs: Never, -) -> Callable[[...], SlashCommand]: +) -> Callable[..., SlashCommand]: """Decorator for slash commands that invokes :func:`application_command`. .. versionadded:: 2.0 @@ -2040,7 +2040,7 @@ def user_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, **kwargs: Never, ) -> Callable[..., UserCommand]: """Decorator for user commands that invokes :func:`application_command`. @@ -2081,7 +2081,7 @@ def message_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, **kwargs: Never, ) -> Callable[..., MessageCommand]: """Decorator for message commands that invokes :func:`application_command`. @@ -2112,7 +2112,7 @@ def message_command( def application_command( *, - cls=SlashCommand, + cls: type[C] = SlashCommand, checks: list[Callable[[ApplicationContext], bool]] | None = MISSING, cog: Cog | None = MISSING, contexts: set[InteractionContextType] | None = MISSING, @@ -2125,7 +2125,7 @@ def application_command( integration_types: set[IntegrationType] | None = MISSING, name: str | None = MISSING, name_localizations: dict[str, str] | None = MISSING, - nsfw: bool = False, + nsfw: bool | None = MISSING, options: list[Option] | None = MISSING, parent: SlashCommandGroup | None = MISSING, **kwargs: Any,