Skip to content

Commit d8cb7f1

Browse files
committed
feedback
1 parent 06c7045 commit d8cb7f1

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

docs/guide/interactions/slash_commands.rst

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,19 @@ Some information is logically inferred from the function to populate the slash c
112112
- The :attr:`~.app_commands.Command.name` takes after the function name "meow"
113113
- The :attr:`~.app_commands.Command.description` takes after the docstring "Meow meow meow"
114114

115-
To change them to something else, ``tree.command()`` accepts ``name`` and ``description`` as keyword arguments.
115+
To change them to something else, ``tree.command()`` takes ``name`` and ``description`` keyword-arguments:
116116

117117
.. code-block:: python
118118
119119
@client.tree.command(name="woof", description="Woof woof woof")
120120
async def meow(interaction: discord.Interaction):
121121
pass
122122
123+
# or...
124+
@client.tree.command(name="list")
125+
async def list_(interaction: discord.Interaction):
126+
# prevent shadowing the "list" builtin
127+
123128
If a description isn't provided through ``description`` or by the docstring, an ellipsis "..." is used instead.
124129

125130
Interaction
@@ -171,11 +176,11 @@ Syncing
171176
In order for this command to show up on Discord, the API needs some information regarding it, namely:
172177

173178
- The name and description
174-
- Any parameter names, types, descriptions (covered later)
175-
- Any checks attached (covered later)
176-
- Whether this command is a group (covered later)
177-
- Whether this is a global or local command (covered later)
178-
- Any localisations for the above (covered later)
179+
- Any :ref:`parameter names, types, descriptions <parameters>`
180+
- Any :ref:`checks <checks>` attached
181+
- Whether this command is a :ref:`group <command_groups>`
182+
- Whether this is a :ref:`global or guild command <guild_commands>`
183+
- Any :ref:`localisations <translating>` for the above
179184

180185
Syncing is the process of sending this information, which is done by
181186
calling the :meth:`.CommandTree.sync` method, typically in :meth:`.Client.setup_hook`:
@@ -201,6 +206,8 @@ blocks invocation with this message in red:
201206
As another measure, discord.py will log warnings if there's a mismatch with what Discord provides and
202207
what the bot defines in code during invocation.
203208

209+
.. _parameters:
210+
204211
Parameters
205212
-----------
206213

@@ -416,14 +423,19 @@ For example, to use :func:`~.app_commands.describe` and :func:`~.app_commands.re
416423
Choices
417424
++++++++
418425

419-
To provide the user with a list of options to choose from for an argument, the :func:`.app_commands.choices` decorator can be applied.
426+
:class:`str`, :class:`int` and :class:`float` type parameters can optionally set a list of choices for an argument
427+
using the :func:`.app_commands.choices` decorator.
420428

421-
A user is restricted to selecting a choice and can't type something else.
429+
During invocation, a user is restricted to picking one choice and can't type anything else.
422430

423431
Each individual choice contains 2 fields:
424432

425-
- A name, which is what the user sees
426-
- A value, which is hidden to the user and only visible to the API. Typically, this is either the same as the name or something more developer-friendly. Value types are limited to either a :class:`str`, :class:`int` or :class:`float`.
433+
- A name, which is what the user sees in their client
434+
- A value, which is hidden to the user and only visible to the bot and API.
435+
436+
Typically, this is either the same as the name or something else more developer-friendly.
437+
438+
Value types are limited to either a :class:`str`, :class:`int` or :class:`float`.
427439

428440
To illustrate, the following command has a selection of 3 colours with each value being the colour code:
429441

@@ -566,6 +578,8 @@ Since these are properties, they must be decorated with :class:`property`:
566578
def type(self) -> discord.AppCommandOptionType:
567579
return discord.AppCommandOptionType.user
568580
581+
:meth:`~.Transformer.autocomplete` callbacks can also be defined in-line.
582+
569583
.. _type_conversion:
570584

571585
Type conversion
@@ -604,7 +618,7 @@ Annotating to either :class:`discord.User` or :class:`discord.Member` both point
604618

605619
The actual type given by Discord is dependent on whether the command was invoked in DM-messages or in a guild.
606620

607-
For example, if a parameter annotates to :class:`~discord.Member`, and the command is invoked in a guild,
621+
For example, if a parameter annotates to :class:`~discord.Member`, and the command is invoked in direct-messages,
608622
discord.py will raise an error since the actual type given by Discord,
609623
:class:`~discord.User`, is incompatible with :class:`~discord.Member`.
610624

@@ -633,6 +647,8 @@ To accept member and user, regardless of where the command was invoked, place bo
633647
634648
await interaction.response.send_message(info)
635649
650+
.. _command_groups:
651+
636652
Command groups
637653
---------------
638654

@@ -720,6 +736,8 @@ can be added on top of a subclass to apply to the group, for example:
720736
721737
Due to a Discord limitation, individual subcommands cannot have differing official-checks.
722738

739+
.. _guild_commands:
740+
723741
Guild commands
724742
---------------
725743

@@ -773,6 +791,8 @@ to copy all global commands to a certain guild for syncing:
773791
774792
You'll typically find this syncing paradigm in some of the examples in the repository.
775793

794+
.. _checks:
795+
776796
Checks
777797
-------
778798

@@ -833,7 +853,7 @@ To prevent this, :func:`~.app_commands.guild_only` can also be added.
833853

834854
.. warning::
835855

836-
This can be overriden to a different set of permissions by server administrators through the "Integrations" tab on the official client,
856+
This can be overridden to a different set of permissions by server administrators through the "Integrations" tab on the official client,
837857
meaning, an invoking user might not actually have the permissions specified in the decorator.
838858

839859
Custom checks
@@ -888,7 +908,7 @@ Error handling
888908
---------------
889909

890910
So far, any exceptions raised within a command callback, any custom checks or in a transformer should just be
891-
printed out in the program's ``stderr`` or through any custom logging handlers.
911+
logged in the program's ``stderr`` or through any custom logging handlers.
892912

893913
In order to catch exceptions, the library uses something called error handlers.
894914

@@ -911,6 +931,8 @@ waiting to be written further:
911931
- creating custom erors to know which check/transformer raised what
912932
- an example logging setup
913933

934+
.. _translating:
935+
914936
Translating
915937
------------
916938

0 commit comments

Comments
 (0)