From 377561844db0a2fe2ea032c9e4d5e98cc90428df Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 11 Mar 2022 07:18:34 -0500 Subject: [PATCH] Raise an error if a child command has default guilds set --- discord/app_commands/commands.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index e0aeab770..47fcf3016 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -370,6 +370,9 @@ class Command(Generic[GroupT, P, T]): callback, '__discord_app_commands_default_guilds__', None ) + if self._guild_ids is not None and self.parent is not None: + raise ValueError('child commands cannot have default guilds set, consider setting them in the parent instead') + def __set_name__(self, owner: Type[Any], name: str) -> None: self._attr = name @@ -1167,7 +1170,12 @@ def guilds(*guild_ids: Union[Snowflake, int]) -> Callable[[T], T]: defaults: List[int] = [g if isinstance(g, int) else g.id for g in guild_ids] def decorator(inner: T) -> T: - if isinstance(inner, (Command, Group)): + if isinstance(inner, Group): + inner._guild_ids = defaults + elif isinstance(inner, Command): + if inner.parent is not None: + raise ValueError('child commands of a group cannot have default guilds set') + inner._guild_ids = defaults else: # Runtime attribute assignment