Skip to content

Commit ec7419c

Browse files
ToothyDevplun1331LulalabyPaillat-dev
authored
fix: πŸ§‘β€πŸ’» Add kwargs explicitly for app-command decorators (#3119)
Co-authored-by: plun1331 <plun1331@gmail.com> Co-authored-by: Lala Sabathil <lala@pycord.dev> Co-authored-by: Paillat <paillat@pycord.dev>
1 parent 1aaa721 commit ec7419c

File tree

2 files changed

+295
-23
lines changed

2 files changed

+295
-23
lines changed

β€Ždiscord/bot.pyβ€Ž

Lines changed: 148 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@
6666
from .utils import MISSING, async_all, find, get
6767

6868
if TYPE_CHECKING:
69+
from typing_extensions import Never
70+
71+
from .cog import Cog
72+
from .commands import Option
73+
from .ext.commands import Cooldown
6974
from .member import Member
75+
from .permissions import Permissions
7076

7177
C = TypeVar("C", bound=MessageCommand | SlashCommand | UserCommand)
7278
CoroFunc = Callable[..., Coroutine[Any, Any, Any]]
@@ -909,7 +915,26 @@ async def callback() -> None:
909915
if not autocomplete_task.done():
910916
autocomplete_task.cancel()
911917

912-
def slash_command(self, **kwargs):
918+
def slash_command(
919+
self,
920+
*,
921+
checks: list[Callable[[ApplicationContext], bool]] | None = MISSING,
922+
cog: Cog | None = MISSING,
923+
contexts: set[InteractionContextType] | None = MISSING,
924+
cooldown: Cooldown | None = MISSING,
925+
default_member_permissions: Permissions | None = MISSING,
926+
description: str | None = MISSING,
927+
description_localizations: dict[str, str] | None = MISSING,
928+
guild_ids: list[int] | None = MISSING,
929+
guild_only: bool | None = MISSING,
930+
integration_types: set[IntegrationType] | None = MISSING,
931+
name: str | None = MISSING,
932+
name_localizations: dict[str, str] | None = MISSING,
933+
nsfw: bool | None = MISSING,
934+
options: list[Option] | None = MISSING,
935+
parent: SlashCommandGroup | None = MISSING,
936+
**kwargs: Never,
937+
) -> Callable[..., SlashCommand]:
913938
"""A shortcut decorator for adding a slash command to the bot.
914939
This is equivalent to using :meth:`application_command`, providing
915940
the :class:`SlashCommand` class.
@@ -922,9 +947,42 @@ def slash_command(self, **kwargs):
922947
A decorator that converts the provided function into a :class:`.SlashCommand`,
923948
adds it to the bot, and returns it.
924949
"""
925-
return self.application_command(cls=SlashCommand, **kwargs)
950+
return self.application_command(
951+
cls=SlashCommand,
952+
checks=checks,
953+
cog=cog,
954+
contexts=contexts,
955+
cooldown=cooldown,
956+
default_member_permissions=default_member_permissions,
957+
description=description,
958+
description_localizations=description_localizations,
959+
guild_ids=guild_ids,
960+
guild_only=guild_only,
961+
integration_types=integration_types,
962+
name=name,
963+
name_localizations=name_localizations,
964+
nsfw=nsfw,
965+
options=options,
966+
parent=parent,
967+
**kwargs,
968+
)
926969

927-
def user_command(self, **kwargs):
970+
def user_command(
971+
self,
972+
*,
973+
checks: list[Callable[[ApplicationContext], bool]] | None = MISSING,
974+
cog: Cog | None = MISSING,
975+
contexts: set[InteractionContextType] | None = MISSING,
976+
cooldown: Cooldown | None = MISSING,
977+
default_member_permissions: Permissions | None = MISSING,
978+
guild_ids: list[int] | None = MISSING,
979+
guild_only: bool | None = MISSING,
980+
integration_types: set[IntegrationType] | None = MISSING,
981+
name: str | None = MISSING,
982+
name_localizations: dict[str, str] | None = MISSING,
983+
nsfw: bool | None = MISSING,
984+
**kwargs: Never,
985+
) -> Callable[..., UserCommand]:
928986
"""A shortcut decorator for adding a user command to the bot.
929987
This is equivalent to using :meth:`application_command`, providing
930988
the :class:`UserCommand` class.
@@ -937,9 +995,38 @@ def user_command(self, **kwargs):
937995
A decorator that converts the provided function into a :class:`.UserCommand`,
938996
adds it to the bot, and returns it.
939997
"""
940-
return self.application_command(cls=UserCommand, **kwargs)
998+
return self.application_command(
999+
cls=UserCommand,
1000+
checks=checks,
1001+
cog=cog,
1002+
contexts=contexts,
1003+
cooldown=cooldown,
1004+
default_member_permissions=default_member_permissions,
1005+
guild_ids=guild_ids,
1006+
guild_only=guild_only,
1007+
integration_types=integration_types,
1008+
name=name,
1009+
name_localizations=name_localizations,
1010+
nsfw=nsfw,
1011+
**kwargs,
1012+
)
9411013

942-
def message_command(self, **kwargs):
1014+
def message_command(
1015+
self,
1016+
*,
1017+
checks: list[Callable[[ApplicationContext], bool]] | None = MISSING,
1018+
cog: Cog | None = MISSING,
1019+
contexts: set[InteractionContextType] | None = MISSING,
1020+
cooldown: Cooldown | None = MISSING,
1021+
default_member_permissions: Permissions | None = MISSING,
1022+
guild_ids: list[int] | None = MISSING,
1023+
guild_only: bool | None = MISSING,
1024+
integration_types: set[IntegrationType] | None = MISSING,
1025+
name: str | None = MISSING,
1026+
name_localizations: dict[str, str] | None = MISSING,
1027+
nsfw: bool | None = MISSING,
1028+
**kwargs: Never,
1029+
) -> Callable[..., MessageCommand]:
9431030
"""A shortcut decorator for adding a message command to the bot.
9441031
This is equivalent to using :meth:`application_command`, providing
9451032
the :class:`MessageCommand` class.
@@ -952,9 +1039,43 @@ def message_command(self, **kwargs):
9521039
A decorator that converts the provided function into a :class:`.MessageCommand`,
9531040
adds it to the bot, and returns it.
9541041
"""
955-
return self.application_command(cls=MessageCommand, **kwargs)
1042+
return self.application_command(
1043+
cls=MessageCommand,
1044+
checks=checks,
1045+
cog=cog,
1046+
contexts=contexts,
1047+
cooldown=cooldown,
1048+
default_member_permissions=default_member_permissions,
1049+
guild_ids=guild_ids,
1050+
guild_only=guild_only,
1051+
integration_types=integration_types,
1052+
name=name,
1053+
name_localizations=name_localizations,
1054+
nsfw=nsfw,
1055+
**kwargs,
1056+
)
9561057

957-
def application_command(self, cls: type[C] = SlashCommand, **kwargs):
1058+
def application_command(
1059+
self,
1060+
*,
1061+
cls: type[C] = SlashCommand,
1062+
checks: list[Callable[[ApplicationContext], bool]] | None = MISSING,
1063+
cog: Cog | None = MISSING,
1064+
contexts: set[InteractionContextType] | None = MISSING,
1065+
cooldown: Cooldown | None = MISSING,
1066+
default_member_permissions: Permissions | None = MISSING,
1067+
description: str | None = MISSING,
1068+
description_localizations: dict[str, str] | None = MISSING,
1069+
guild_ids: list[int] | None = MISSING,
1070+
guild_only: bool | None = MISSING,
1071+
integration_types: set[IntegrationType] | None = MISSING,
1072+
name: str | None = MISSING,
1073+
name_localizations: dict[str, str] | None = MISSING,
1074+
nsfw: bool | None = MISSING,
1075+
options: list[Option] | None = MISSING,
1076+
parent: SlashCommandGroup | None = MISSING,
1077+
**kwargs: Any,
1078+
) -> Callable[..., C]:
9581079
"""A shortcut decorator that converts the provided function into
9591080
an application command via :func:`command` and adds it to
9601081
the internal command list via :meth:`~.Bot.add_application_command`.
@@ -976,6 +1097,26 @@ class be provided, it must be a subclass of either
9761097
adds it to the bot, and returns it.
9771098
"""
9781099

1100+
params = {
1101+
"checks": checks,
1102+
"cog": cog,
1103+
"contexts": contexts,
1104+
"cooldown": cooldown,
1105+
"default_member_permissions": default_member_permissions,
1106+
"description": description,
1107+
"description_localizations": description_localizations,
1108+
"guild_ids": guild_ids,
1109+
"guild_only": guild_only,
1110+
"integration_types": integration_types,
1111+
"name": name,
1112+
"name_localizations": name_localizations,
1113+
"nsfw": nsfw,
1114+
"options": options,
1115+
"parent": parent,
1116+
**kwargs,
1117+
}
1118+
kwargs = {k: v for k, v in params.items() if v is not MISSING}
1119+
9791120
def decorator(func) -> C:
9801121
result = command(cls=cls, **kwargs)(func)
9811122
self.add_application_command(result)

0 commit comments

Comments
Β (0)