Skip to content

Commit 3f1cc8e

Browse files
committed
Support subclassing SlashCommandGroup
1 parent 16e7aff commit 3f1cc8e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

discord/commands/commands.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
385385
validate_chat_input_description(description)
386386
self.description: str = description
387387
self.parent = kwargs.get('parent')
388-
self.is_subcommand: bool = self.parent is not None
389388

390389
self.cog = None
391390

@@ -472,6 +471,10 @@ def _is_typing_union(self, annotation):
472471
def _is_typing_optional(self, annotation):
473472
return self._is_typing_union(annotation) and type(None) in annotation.__args__ # type: ignore
474473

474+
@property
475+
def is_subcommand(self) -> bool:
476+
return self.parent is not None
477+
475478
def to_dict(self) -> Dict:
476479
as_dict = {
477480
"name": self.name,
@@ -719,8 +722,15 @@ class SlashCommandGroup(ApplicationCommand, Option):
719722

720723
def __new__(cls, *args, **kwargs) -> SlashCommandGroup:
721724
self = super().__new__(cls)
722-
723725
self.__original_kwargs__ = kwargs.copy()
726+
727+
self.__initial_commands__ = []
728+
for i, c in cls.__dict__.items():
729+
if isinstance(c, (SlashCommand, SlashCommandGroup)):
730+
print(c.parent)
731+
c.parent = self
732+
self.__initial_commands__.append(c)
733+
724734
return self
725735

726736
def __init__(
@@ -738,7 +748,7 @@ def __init__(
738748
name=name,
739749
description=description,
740750
)
741-
self.subcommands: List[Union[SlashCommand, SlashCommandGroup]] = []
751+
self.subcommands: List[Union[SlashCommand, SlashCommandGroup]] = self.__initial_commands__
742752
self.guild_ids = guild_ids
743753
self.parent = parent
744754
self.checks = []

0 commit comments

Comments
 (0)