Skip to content

Commit 0ad3206

Browse files
authored
Error handling and subcommand documentation.
1 parent 1da3fe1 commit 0ad3206

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/gettingstarted.rst

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ But what about buttons?
315315
-----------------------
316316
This library supports components (buttons, actionrows, selects, etc.). Take a look here: `components`_.
317317

318-
Adding Context Menus.
318+
Making a message/menu command.
319319
*********************
320320
Lucky for you, this library has recently added support for context menus! Let's take a look into how they're designed.
321321

@@ -401,8 +401,50 @@ The decision has been made that this will not be implemented because of two reas
401401
for any responses would be currently pointless. Additionally, component listening is already a built-in feature that does not require further customized and new decorators
402402
for explicitly context menus, as they're more universal.
403403

404+
Nested commands as subcommands.
405+
*******************************
406+
Before you get into learning how to create a subcommand, please be sure to read up on the documentation above given for how slash commands are made.
407+
408+
Subcommands are way to "nest" your slash commands under one (or more) given names, as either a "base" name or a "grouping" of an existing base. When this is said, it will initially appear very confusing. Let's use the table shown below as a way to introduce the new fields/properties that can be applied for a slash command to become a subcommand:
409+
410+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
411+
| **Field** | **Type** | **Description** |
412+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
413+
| base | string | The name of the subcommand "base." |
414+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
415+
| subcommand_group | string | The name for the group of commands under the "base." Field is optional. |
416+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
417+
| base_description | string | The description when the base is active in the UX chat bar. Defaults to ``None``. |
418+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
419+
| subcommand_group_description | string | The name for the group of commands under the "base." Defaults to ``None``. |
420+
+------------------------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
421+
422+
This table is importantly distinguishing the **library's** naming conventions and not the way that th eDiscord API handles it. The API does subcommand grouping and bases through the options of a slash command, so we decided to create a decorator instead to make this easy for bot developers alike to use. We will not be giving a JSON example of this because of this reason.
423+
424+
.. code-block :: python
425+
426+
# This will appear as "/bot latency" as latency is not an option,
427+
# but apart of the command name itself.
428+
@slash.subcommand(base="bot",
429+
name="latency",
430+
description="Returns the bot's latency.")
431+
async def bot_latency(ctx):
432+
await ctx.send(f"Hello! {round(bot.latency * 1000)} ms.")
433+
434+
If you would like to add a group instead, you may simply base the ``subcommand_group``` kwarg into the decorator. Please note that the slash command limit is 25 commands per subcommand group per subcommand base. (Laymen's term for 25 subcommands in a group, and 25 groups in a base. This is not a global exception and may also apply as a limitation for guild commands.)
435+
436+
Handling my errors.
437+
*******************
438+
439+
Thankfully, we try to make a majority of our error handling very simple. If you would like to learn more about how to handle your errors, please refer to our `errors`_ page.
440+
If you are looking for listener events, then check our `listeners`_ page instead.
441+
442+
As a side-note, as of version 3.0, message/menu commands (context menus) are handled under the ``on_slash_command_error`` event.
443+
404444
.. _quickstart: quickstart.html
405445
.. _components: components.html
446+
.. _errors: discord_slash.error.html
447+
.. _listeners: events.html
406448
.. _ApplicationCommandOptionType: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype
407449
.. _ApplicationCommandOptionChoice: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice
408450
.. _ApplicationCommandOption: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption

0 commit comments

Comments
 (0)