Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 3775618

Browse files
committed
Raise an error if a child command has default guilds set
1 parent f54c4ca commit 3775618

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

discord/app_commands/commands.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ def __init__(
370370
callback, '__discord_app_commands_default_guilds__', None
371371
)
372372

373+
if self._guild_ids is not None and self.parent is not None:
374+
raise ValueError('child commands cannot have default guilds set, consider setting them in the parent instead')
375+
373376
def __set_name__(self, owner: Type[Any], name: str) -> None:
374377
self._attr = name
375378

@@ -1167,7 +1170,12 @@ async def bonk(interaction: discord.Interaction):
11671170
defaults: List[int] = [g if isinstance(g, int) else g.id for g in guild_ids]
11681171

11691172
def decorator(inner: T) -> T:
1170-
if isinstance(inner, (Command, Group)):
1173+
if isinstance(inner, Group):
1174+
inner._guild_ids = defaults
1175+
elif isinstance(inner, Command):
1176+
if inner.parent is not None:
1177+
raise ValueError('child commands of a group cannot have default guilds set')
1178+
11711179
inner._guild_ids = defaults
11721180
else:
11731181
# Runtime attribute assignment

0 commit comments

Comments
 (0)