@@ -8,6 +8,47 @@ def cog_slash(*,
8
8
auto_convert : dict = None ,
9
9
guild_ids : typing .List [int ] = None ,
10
10
options : typing .List [dict ] = None ):
11
+ """
12
+ Decorator for Cog to add slash command.\n
13
+ Almost same as :func:`.client.SlashCommand.slash`.
14
+
15
+ Example:
16
+ .. code-block:: python
17
+
18
+ class ExampleCog(commands.Cog):
19
+ def __init__(self, bot):
20
+ if not hasattr(bot, "slash"):
21
+ # Creates new SlashCommand instance to bot if bot doesn't have.
22
+ bot.slash = SlashCommand(bot, override_type=True)
23
+ self.bot = bot
24
+ self.bot.slash.get_cog_commands(self)
25
+
26
+ def cog_unload(self):
27
+ self.bot.slash.remove_cog_commands(self)
28
+
29
+ @cog_ext.cog_slash(name="ping")
30
+ async def ping(self, ctx: SlashContext):
31
+ await ctx.send(content="Pong!")
32
+
33
+ :param name: Name of the slash command. Default name of the coroutine.
34
+ :type name: str
35
+ :param description: Description of the slash command. Default ``None``.
36
+ :type description: str
37
+ :param auto_convert: Dictionary of how to convert option values. Default ``None``.
38
+ :type auto_convert: dict
39
+ :param guild_ids: List of Guild ID of where the command will be used. Default ``None``, which will be global command.
40
+ :type guild_ids: List[int]
41
+ :param options: Options of the slash command. This will affect ``auto_convert`` and command data at Discord API. Default ``None``.
42
+ :type options: List[dict]
43
+ """
44
+ if options :
45
+ # Overrides original auto_convert.
46
+ auto_convert = {}
47
+ for x in options :
48
+ if x ["type" ] < 3 :
49
+ raise Exception ("Please use `cog_subcommand()` decorator for cog subcommands!" )
50
+ auto_convert [x ["name" ]] = x ["type" ]
51
+
11
52
def wrapper (cmd ):
12
53
_cmd = {
13
54
"func" : cmd ,
@@ -28,6 +69,41 @@ def cog_subcommand(*,
28
69
description : str = None ,
29
70
auto_convert : dict = None ,
30
71
guild_ids : typing .List [int ] = None ):
72
+ """
73
+ Decorator for Cog to add subcommand.\n
74
+ Almost same as :func:`.client.SlashCommand.subcommand`.
75
+
76
+ Example:
77
+ .. code-block:: python
78
+
79
+ class ExampleCog(commands.Cog):
80
+ def __init__(self, bot):
81
+ if not hasattr(bot, "slash"):
82
+ # Creates new SlashCommand instance to bot if bot doesn't have.
83
+ bot.slash = SlashCommand(bot, override_type=True)
84
+ self.bot = bot
85
+ self.bot.slash.get_cog_commands(self)
86
+
87
+ def cog_unload(self):
88
+ self.bot.slash.remove_cog_commands(self)
89
+
90
+ @cog_ext.cog_subcommand(base="group", name="say")
91
+ async def group_say(self, ctx: SlashContext, text: str):
92
+ await ctx.send(content=text)
93
+
94
+ :param base: Name of the base command.
95
+ :type base: str
96
+ :param subcommand_group: Name of the subcommand group, if any. Default ``None`` which represents there is no sub group.
97
+ :type subcommand_group: str
98
+ :param name: Name of the subcommand. Default name of the coroutine.
99
+ :type name: str
100
+ :param description: Description of the subcommand. Default ``None``.
101
+ :type description: str
102
+ :param auto_convert: Dictionary of how to convert option values. Default ``None``.
103
+ :type auto_convert: dict
104
+ :param guild_ids: List of guild ID of where the command will be used. Default ``None``, which will be global command.
105
+ :type guild_ids: List[int]
106
+ """
31
107
def wrapper (cmd ):
32
108
_sub = {
33
109
"func" : cmd ,
0 commit comments