Skip to content

Commit e0bb2c7

Browse files
committed
Add documentation and error raising.
1 parent 36e154b commit e0bb2c7

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

discord_slash/error.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ class AlreadyResponded(SlashCommandError):
8888
"""
8989
The interaction was already responded to
9090
"""
91+
92+
class ContextMenuError(SlashCommandError):
93+
"""
94+
Special error given for context menu creation/callback issues.
95+
"""

docs/gettingstarted.rst

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

318+
Adding Context Menus.
319+
*********************
320+
Lucky for you, this library has recently added support for context menus! Let's take a look into how they're designed.
321+
322+
A menu command (context menu) is an easy way for bot developers to program optionless and choiceless commands into their bot
323+
which can be easily accessible by right clicking on a user and/or message present. Below is a table of the supported keys and
324+
values:
325+
326+
+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
327+
| **Field** | **Type** | **Description** |
328+
+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
329+
| name | string | The name of the context menu command. |
330+
+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
331+
| type | int | An `ApplicationCommandType`_. |
332+
+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
333+
334+
The following table below represents how it would be shown as a JSON object:
335+
336+
.. code-block:: python
337+
338+
{
339+
"name": "Name of my command.",
340+
"type": 3
341+
}
342+
343+
The following table explains more about the `type` parameter being passed, which there are three of: `CHAT_INPUT`, `USER` and `MESSAGE`. By default, the type will
344+
always be the first. This is because it is a registered type that is used to process slash commands, and should not be used for when you are declaring context menu
345+
commands in your bot's code at all:
346+
347+
+------------+-----------+
348+
| **Name** | **Value** |
349+
+------------+-----------+
350+
| CHAT_INPUT | 1 |
351+
+------------+-----------+
352+
| USER | 2 |
353+
+------------+-----------+
354+
| MESSAGE | 3 |
355+
+------------+-----------+
356+
357+
Unlike `manage_commands` and `manage_components`, you will have to use a decorator for now to register them:
358+
359+
.. code-block :: python
360+
361+
from discord_slash.model import ContextMenuType
362+
363+
@slash.context_menu(ContextMenuType.MESSAGE,
364+
name="commandname",
365+
guild_ids=[789032594456576001])
366+
async def commandname(ctx: MenuContext):
367+
await ctx.send(
368+
content="Responded!",
369+
hidden=True
370+
)
371+
372+
The `@slash.context_menu` decorator takes in the context type as given (to either appear when you right-click on a user or when you right-click on a message) as well
373+
as the name of the command, and any guild IDs if given if you would like to make it applicable to only a guild. **We only accept connected names** for the time being,
374+
although context menus will have the ability to have spaces in their name in the future when development further progresses.
375+
376+
Hey, what about component/[X] listening?
377+
----------------------------------------
378+
The decision has been made that this will not be implemented because of two reasons: context menus currently have no ability to hold any options or choices, so listening
379+
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
380+
for explicitly context menus, as they're more universal.
381+
318382
.. _quickstart: quickstart.html
319383
.. _components: components.html
320384
.. _ApplicationCommandOptionType: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype
321385
.. _ApplicationCommandOptionChoice: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice
322386
.. _ApplicationCommandOption: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption
323387
.. _ApplicationCommandPermissionType: https://discord.com/developers/docs/interactions/slash-commands#applicationcommandpermissions
388+
.. _ApplicationCommandType: https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types

0 commit comments

Comments
 (0)