Skip to content

Commit 03e3c93

Browse files
committed
Create slash group class decorator
1 parent 5c1ef1d commit 03e3c93

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

discord/bot.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,47 @@ def command(self, **kwargs):
532532
"""
533533
return self.application_command(**kwargs)
534534

535-
def command_group(
536-
self, name: str, description: str, guild_ids=None
535+
def create_group(
536+
self, name: str, description: str, guild_ids: Optional[List[int]] = None
537537
) -> SlashCommandGroup:
538-
# TODO: Write documentation for this. I'm not familiar enough with what this function does to do it myself.
538+
"""A shortcut method that creates a slash command group with no subcommands and adds it to the internal
539+
command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
540+
541+
.. versionadded:: 2.0
542+
543+
Returns
544+
--------
545+
SlashCommandGroup
546+
The slash command group that was created.
547+
"""
539548
group = SlashCommandGroup(name, description, guild_ids)
540549
self.add_application_command(group)
541550
return group
542551

552+
def group(
553+
self,
554+
name: str,
555+
description: str,
556+
guild_ids: Optional[List[int]] = None,
557+
) -> Callable[[Type[SlashCommandGroup]], SlashCommandGroup]:
558+
"""A shortcut decorator that initializes the provided subclass of :class:`.SlashCommandGroup`
559+
and adds it to the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
560+
561+
.. versionadded:: 2.0
562+
563+
Returns
564+
--------
565+
Callable[[Type[SlashCommandGroup]], SlashCommandGroup]
566+
The slash command group that was created.
567+
"""
568+
def inner(cls: Type[SlashCommandGroup]) -> SlashCommandGroup:
569+
group = cls(name, description, guild_ids=guild_ids)
570+
self.add_application_command(group)
571+
return group
572+
return inner
573+
574+
slash_group = group
575+
543576
async def get_application_context(
544577
self, interaction: Interaction, cls=None
545578
) -> ApplicationContext:

0 commit comments

Comments
 (0)