@@ -12,6 +12,11 @@ class SlashCommand:
1212
1313 :param client: discord.py Bot class. Although it accepts :class:`discord.Client` at init, using it is not allowed since :class:`discord.Client` doesn't support :func:`add_listener`.
1414 :type client: Union[discord.Client, discord.ext.commands.Bot]
15+
16+ :ivar _discord: Discord client of this client.
17+ :ivar commands: Dictionary of the registered commands via :func:`.slash` decorator.
18+ :ivar req: :class:`.http.SlashCommandRequest` of this client.
19+ :ivar logger: Logger of this client.
1520 """
1621 def __init__ (self ,
1722 client : typing .Union [discord .Client ,
@@ -21,18 +26,38 @@ def __init__(self,
2126 raise Exception ("Currently only commands.Bot is supported." )
2227 self ._discord = client
2328 self .commands = {}
24- self .http = http .SlashCommandRequest ()
29+ self .req = http .SlashCommandRequest ()
2530 self .logger = logging .getLogger ("discord_slash" )
2631 self ._discord .add_listener (self .on_socket_response )
2732
28- def slash (self , name = None ):
33+ def slash (self , name = None , auto_convert : dict = None ):
2934 """
3035 Decorator that registers coroutine as a slash command.\n
31- 1 arg is required for ctx(:func:`discord_slash.model.SlashContext`), and if your slash command has some args, then those args are also required.\n
32- All args are passed in order.\n
33- Note that Role, User, and Channel types are passed as id, since API doesn't give type of the option for now.
36+ 1 arg is required for ctx(:class:`.model.SlashContext`), and if your slash command has some args, then those args are also required.\n
37+ All args are passed in order.
38+
39+ .. note::
40+ Role, User, and Channel types are passed as id, since API doesn't give type of the option for now.
41+
42+ .. warning::
43+ Unlike discord.py's command, ``*args``, keyword-only args, converters, etc. are NOT supported.
44+
45+ Example:
46+
47+ .. code-block:: python
48+
49+ @slash.slash(name="ping")
50+ async def _slash(ctx): # Normal usage.
51+ await ctx.send(text=f"Pong! (`{round(bot.latency*1000)}`ms)")
52+
53+
54+ @slash.slash(name="pick")
55+ async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
56+ await ctx.send(text=str(random.choice([choice1, choice2])))
3457
3558 :param name: Name of the slash command.
59+ :param auto_convert: Not implemented.
60+ :type auto_convert: dict
3661 """
3762 def wrapper (cmd ):
3863 self .commands [cmd .__name__ if not name else name ] = cmd
@@ -57,8 +82,10 @@ def process_options(self, options: dict) -> list:
5782
5883 async def on_socket_response (self , msg ):
5984 """
60- This event listener is automatically registered at initialization of this class.\n
61- DO NOT MANUALLY REGISTER, OVERRIDE, OR WHATEVER ACTION TO THIS COROUTINE UNLESS YOU KNOW WHAT YOU ARE DOING.
85+ This event listener is automatically registered at initialization of this class.
86+
87+ .. warning::
88+ DO NOT MANUALLY REGISTER, OVERRIDE, OR WHATEVER ACTION TO THIS COROUTINE UNLESS YOU KNOW WHAT YOU ARE DOING.
6289
6390 :param msg: Gateway message.
6491 """
@@ -67,5 +94,5 @@ async def on_socket_response(self, msg):
6794 to_use = msg ["d" ]
6895 if to_use ["data" ]["name" ] in self .commands .keys ():
6996 args = [x ["value" ] for x in to_use ["data" ]["options" ]] if "options" in to_use ["data" ] else []
70- ctx = model .SlashContext (self .http , to_use , self ._discord )
97+ ctx = model .SlashContext (self .req , to_use , self ._discord )
7198 await self .commands [to_use ["data" ]["name" ]](ctx , * args )
0 commit comments