30
30
import functools
31
31
import inspect
32
32
from collections import OrderedDict
33
- from typing import Any , Callable , Dict , List , Optional , Union , TYPE_CHECKING
33
+ from typing import Any , Callable , Dict , List , Optional , Type , Union , TYPE_CHECKING
34
34
35
35
from ..enums import SlashCommandOptionType , ChannelType
36
36
from ..member import Member
@@ -786,7 +786,7 @@ def wrap(func) -> SlashCommand:
786
786
787
787
return wrap
788
788
789
- def command_group (self , name , description ) -> SlashCommandGroup :
789
+ def create_group (self , name , description ) -> SlashCommandGroup :
790
790
if self .parent is not None :
791
791
# TODO: Improve this error message
792
792
raise Exception ("Subcommands can only be nested once" )
@@ -795,6 +795,47 @@ def command_group(self, name, description) -> SlashCommandGroup:
795
795
self .subcommands .append (sub_command_group )
796
796
return sub_command_group
797
797
798
+ def subgroup (
799
+ self ,
800
+ name : str ,
801
+ description : str = None ,
802
+ guild_ids : Optional [List [int ]] = None ,
803
+ ) -> Callable [[Type [SlashCommandGroup ]], SlashCommandGroup ]:
804
+ """A shortcut decorator that initializes the provided subclass of :class:`.SlashCommandGroup`
805
+ as a subgroup.
806
+
807
+ .. versionadded:: 2.0
808
+
809
+ Parameters
810
+ ----------
811
+ name: :class:`str`
812
+ The name of the group to create.
813
+ description: Optional[:class:`str`]
814
+ The description of the group to create.
815
+ guild_ids: Optional[List[:class:`int`]]
816
+ A list of the IDs of each guild this group should be added to, making it a guild command.
817
+ This will be a global command if ``None`` is passed.
818
+
819
+ Returns
820
+ --------
821
+ Callable[[Type[SlashCommandGroup]], SlashCommandGroup]
822
+ The slash command group that was created.
823
+ """
824
+ def inner (cls : Type [SlashCommandGroup ]) -> SlashCommandGroup :
825
+ group = cls (
826
+ name ,
827
+ description or (
828
+ inspect .cleandoc (cls .__doc__ ).splitlines ()[0 ]
829
+ if cls .__doc__ is not None
830
+ else "No description provided"
831
+ ),
832
+ guild_ids = guild_ids ,
833
+ parent = self ,
834
+ )
835
+ self .subcommands .append (group )
836
+ return group
837
+ return inner
838
+
798
839
async def _invoke (self , ctx : ApplicationContext ) -> None :
799
840
option = ctx .interaction .data ["options" ][0 ]
800
841
command = find (lambda x : x .name == option ["name" ], self .subcommands )
0 commit comments