You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a description isn't provided through ``description`` or by the docstring, an ellipsis "..." is used instead.
124
129
125
130
Interaction
@@ -171,11 +176,11 @@ Syncing
171
176
In order for this command to show up on Discord, the API needs some information regarding it, namely:
172
177
173
178
- 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
179
184
180
185
Syncing is the process of sending this information, which is done by
181
186
calling the :meth:`.CommandTree.sync` method, typically in :meth:`.Client.setup_hook`:
@@ -201,6 +206,8 @@ blocks invocation with this message in red:
201
206
As another measure, discord.py will log warnings if there's a mismatch with what Discord provides and
202
207
what the bot defines in code during invocation.
203
208
209
+
.. _parameters:
210
+
204
211
Parameters
205
212
-----------
206
213
@@ -416,14 +423,19 @@ For example, to use :func:`~.app_commands.describe` and :func:`~.app_commands.re
416
423
Choices
417
424
++++++++
418
425
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.
420
428
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.
422
430
423
431
Each individual choice contains 2 fields:
424
432
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`.
427
439
428
440
To illustrate, the following command has a selection of 3 colours with each value being the colour code:
429
441
@@ -566,6 +578,8 @@ Since these are properties, they must be decorated with :class:`property`:
566
578
deftype(self) -> discord.AppCommandOptionType:
567
579
return discord.AppCommandOptionType.user
568
580
581
+
:meth:`~.Transformer.autocomplete` callbacks can also be defined in-line.
582
+
569
583
.. _type_conversion:
570
584
571
585
Type conversion
@@ -604,7 +618,7 @@ Annotating to either :class:`discord.User` or :class:`discord.Member` both point
604
618
605
619
The actual type given by Discord is dependent on whether the command was invoked in DM-messages or in a guild.
606
620
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,
608
622
discord.py will raise an error since the actual type given by Discord,
609
623
:class:`~discord.User`, is incompatible with :class:`~discord.Member`.
610
624
@@ -633,6 +647,8 @@ To accept member and user, regardless of where the command was invoked, place bo
633
647
634
648
await interaction.response.send_message(info)
635
649
650
+
.. _command_groups:
651
+
636
652
Command groups
637
653
---------------
638
654
@@ -720,6 +736,8 @@ can be added on top of a subclass to apply to the group, for example:
720
736
721
737
Due to a Discord limitation, individual subcommands cannot have differing official-checks.
722
738
739
+
.. _guild_commands:
740
+
723
741
Guild commands
724
742
---------------
725
743
@@ -773,6 +791,8 @@ to copy all global commands to a certain guild for syncing:
773
791
774
792
You'll typically find this syncing paradigm in some of the examples in the repository.
775
793
794
+
.. _checks:
795
+
776
796
Checks
777
797
-------
778
798
@@ -833,7 +853,7 @@ To prevent this, :func:`~.app_commands.guild_only` can also be added.
833
853
834
854
.. warning::
835
855
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,
837
857
meaning, an invoking user might not actually have the permissions specified in the decorator.
838
858
839
859
Custom checks
@@ -888,7 +908,7 @@ Error handling
888
908
---------------
889
909
890
910
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.
892
912
893
913
In order to catch exceptions, the library uses something called error handlers.
894
914
@@ -911,6 +931,8 @@ waiting to be written further:
911
931
- creating custom erors to know which check/transformer raised what
0 commit comments