From 5741ad93682eda38f318b6d6c52d49e28f594134 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 9 Mar 2022 19:11:30 -0500 Subject: [PATCH] Change default guild IDs attribute to persist on copy --- discord/app_commands/commands.py | 11 ++++++----- discord/app_commands/tree.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index 156e1cae0..5311fb147 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -314,8 +314,6 @@ class Command(Generic[GroupT, P, T]): The parent application command. ``None`` if there isn't one. """ - __discord_app_commands_default_guilds__: List[int] - def __init__( self, *, @@ -332,6 +330,7 @@ class Command(Generic[GroupT, P, T]): self.binding: Optional[GroupT] = None self.on_error: Optional[Error[GroupT]] = None self._params: Dict[str, CommandParameter] = _extract_parameters_from_callback(callback, callback.__globals__) + self._guild_ids: Optional[List[int]] = getattr(callback, '__discord_app_commands_default_guilds__', None) def __set_name__(self, owner: Type[Any], name: str) -> None: self._attr = name @@ -345,6 +344,7 @@ class Command(Generic[GroupT, P, T]): cls = self.__class__ copy = cls.__new__(cls) copy.name = self.name + copy._guild_ids = self._guild_ids copy.description = self.description copy._attr = self._attr copy._callback = self._callback @@ -628,7 +628,6 @@ class Group: """ __discord_app_commands_group_children__: ClassVar[List[Union[Command, Group]]] = [] - __discord_app_commands_default_guilds__: List[int] __discord_app_commands_group_name__: str = MISSING __discord_app_commands_group_description__: str = MISSING @@ -636,7 +635,7 @@ class Group: if not cls.__discord_app_commands_group_children__: cls.__discord_app_commands_group_children__ = children = [ member - for name, member in cls.__dict__.items() + for member in cls.__dict__.values() if isinstance(member, (Group, Command)) and member.parent is None ] @@ -674,6 +673,7 @@ class Group: self.name: str = name if name is not MISSING else cls.__discord_app_commands_group_name__ self.description: str = description or cls.__discord_app_commands_group_description__ self._attr: Optional[str] = None + self._guild_ids: Optional[List[int]] = None if not self.description: raise TypeError('groups must have a description') @@ -699,6 +699,7 @@ class Group: cls = self.__class__ copy = cls.__new__(cls) copy.name = self.name + copy._guild_ids = self._guild_ids copy.description = self.description copy.parent = self.parent copy._attr = self._attr @@ -1127,7 +1128,7 @@ def guilds(*guild_ids: Union[Snowflake, int]) -> Callable[[T], T]: def decorator(inner: T) -> T: if isinstance(inner, (Command, Group)): - inner.__discord_app_commands_default_guilds__ = defaults + inner._guild_ids = defaults else: # Runtime attribute assignment inner.__discord_app_commands_default_guilds__ = defaults # type: ignore diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index 2f2bc63aa..be16b0c3e 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -65,7 +65,7 @@ def _retrieve_guild_ids( # If no arguments are given then it should default to the ones # given to the guilds(...) decorator or None for global. if guild is MISSING: - return getattr(command, '__discord_app_commands_default_guilds__', None) + return getattr(command, '_guild_ids', None) # guilds=[] is the same as global if len(guilds) == 0: