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
Command names must be lowercase and can only contain `-` and `_` as special symbols and must not contain spaces.
35
+
Command names must be lowercase, can only contain `-` and `_` as special symbols, and must not contain spaces.
36
36
37
-
When testing, it is recommended to use non-global commands, as they sync instantly.
37
+
By default, commands are assumed to be global, meaning they can be used by every server the bot is in. When testing, it is recommended to use non-global commands.
38
38
For that, you can either define `scopes` in every command or set `debug_scope` in the bot instantiation which sets the scope automatically for all commands.
39
39
40
40
You can define non-global commands by passing a list of guild ids to `scopes` in the interaction creation.
This will show up in discord as `/base group command`. There are more ways to add additional subcommands:
67
+
This will show up in discord as `/base group command`. You may also wish to drop the `group` part to have a `/base command` subcommand, which you can do by removing the `group_name` and `group_description` parameters (they are optional).
68
+
69
+
There are more ways to add additional subcommands to the base/group from there:
@@ -106,11 +108,12 @@ This will show up in discord as `/base group command`. There are more ways to ad
106
108
await ctx.send("Hello World")
107
109
```
108
110
109
-
For all of these, the "group" parts are optional, allowing you to do `/base command` instead.
111
+
All of these would create a subcommand called `/base group second_command`.
110
112
111
113
???+ note
112
-
You cannot mix group subcommands and non-group subcommands into one base command - you must either use all group subcommands or normal subcommands.
114
+
Using subcommands makes using the base command unusable - IE, you cannot use `/base` as a normal command.
113
115
116
+
Group subcommands follow a similar logic, as by defining a group, you can no longer create normal subcommands - IE, you cannot use either `/base` or `/base command`.
114
117
115
118
## Options
116
119
@@ -119,13 +122,13 @@ Interactions can also have options. There are a bunch of different [types of opt
|`OptionType.STRING`|`str`| Limit the input to a string. |
122
-
|`OptionType.INTEGER`|`int`| Limit the input to a integer. |
123
-
|`OptionType.NUMBER`|`float`| Limit the input to a float. |
125
+
|`OptionType.INTEGER`|`int`| Limit the input to an integer between -2^53 and 2^53. |
126
+
|`OptionType.NUMBER`|`float`| Limit the input to a float between -2^53 and 2^53. |
124
127
|`OptionType.BOOLEAN`|`bool`| Let the user choose either `True` or `False`. |
125
128
|`OptionType.USER`|`Member` in guilds, else `User`| Let the user choose a discord user from an automatically-generated list of options. |
126
129
|`OptionType.CHANNEL`|`GuildChannel` in guilds, else `DMChannel`| Let the user choose a discord channel from an automatically-generated list of options. |
127
130
|`OptionType.ROLE`|`Role`| Let the user choose a discord role from an automatically-generated list of options. |
128
-
|`OptionType.MENTIONABLE`|`DiscordObject`| Let the user chose any discord mentionable from an automatically generated list of options. |
131
+
|`OptionType.MENTIONABLE`|`Union[Member, User, Role]`| Let the user chose any discord mentionable from an automatically generated list of options. |
129
132
|`OptionType.ATTACHMENT`|`Attachment`| Let the user upload an attachment. |
130
133
131
134
Now that you know all the options you have for options, you can opt into adding options to your interaction.
For more information, please visit the API reference [here](/interactions.py/API Reference/API Reference/models/Internal/application_commands/#interactions.models.internal.application_commands.slash_option).
For more information, please visit the API reference [here](/interactions.py/API Reference/API Reference/models/Internal/application_commands/#interactions.models.internal.application_commands.SlashCommandChoice).
244
255
245
-
## Autocomplete / More than 25 choices needed
256
+
## Autocomplete / More Than 25 Choices Needed
246
257
247
258
If you have more than 25 choices the user can choose from, or you want to give a dynamic list of choices depending on what the user is currently typing, then you will need autocomplete options.
248
259
The downside is that you need to supply the choices on request, making this a bit more tricky to set up.
@@ -269,7 +280,7 @@ from interactions import AutocompleteContext
@@ -349,7 +367,7 @@ There are currently four different ways to define interactions, one does not nee
349
367
await ctx.send(f"You input {integer_option}")
350
368
351
369
bot.add_interaction(
352
-
command=SlashCommand(
370
+
SlashCommand(
353
371
name="my_command",
354
372
description="My first command :)",
355
373
options=[
@@ -359,23 +377,24 @@ There are currently four different ways to define interactions, one does not nee
359
377
required=True,
360
378
type=OptionType.INTEGER
361
379
)
362
-
]
380
+
],
381
+
callback=my_command_function
363
382
)
364
383
)
365
384
```
366
385
367
-
## Restrict commands using permissions
386
+
## Restrict Commands Using Permissions
368
387
369
-
It is possible to disable interactions (slash commands as well as context menus) for users that do not have a set of permissions.
388
+
It is possible to disable application commands (which include slash commands) for users that do not have a set of permissions.
370
389
371
-
This functionality works for **permissions**, not to confuse with roles. If you want to restrict some command if the user does not have a certain role, this cannot be done on the bot side. However, it can be done on the Discord server side, in the Server Settings > Integrations page.
390
+
This functionality works for **permissions**, not to confuse with roles. If you want to restrict some command if the user does not have a certain role, this cannot be done on the bot side. However, it can be done on the Discord server side (in the Server Settings > Integrations page) or through [Checks][checks] as discussed below.
372
391
373
392
!!!warning Administrators
374
393
Remember that administrators of a Discord server have all permissions and therefore will always see the commands.
375
394
376
395
If you do not want admins to be able to overwrite your permissions, or the permissions are not flexible enough for you, you should use [checks][checks].
377
396
378
-
In this example, we will limit access to the command to members with the `MANAGE_EVENTS` and `MANAGE_THREADS` permissions.
397
+
In this example, we will limit access to the command to members with the `MANAGE_EVENTS`*and*`MANAGE_THREADS` permissions.
379
398
There are two ways to define permissions.
380
399
381
400
=== ":one: Decorators"
@@ -427,7 +446,7 @@ There are a few pre-made checks for you to use, and you can simply create your o
427
446
Check that the author is the owner of the bot:
428
447
429
448
```python
430
-
from interactions import SlashContext, check, is_owner, slash_command
449
+
from interactions import check, is_owner
431
450
432
451
@slash_command(name="my_command")
433
452
@check(is_owner())
@@ -439,7 +458,7 @@ There are a few pre-made checks for you to use, and you can simply create your o
439
458
Check that the author's username starts with `a`:
440
459
441
460
```python
442
-
from interactions import BaseContext, SlashContext, check, slash_command
461
+
from interactions import check
443
462
444
463
async def my_check(ctx: BaseContext):
445
464
return ctx.author.username.startswith("a")
@@ -451,33 +470,30 @@ There are a few pre-made checks for you to use, and you can simply create your o
451
470
```
452
471
453
472
=== ":three: Reusing Checks"
454
-
You can reuse checks in extensions by adding them to the extension check list
473
+
While you can simply reuse checks by doing `@check(my_check)` for every command you wish to use the check with, you can also reuse them by making your own decorator wrapping the `@check()` decorator:
If you wish for an error handler for a group of commands, you may wish to check out [Extensions](20 Extensions.md), which allows you both to group commands together and add error handlers to the group.
505
555
506
556
If you want error handling for all commands, you can override the default error listener and define your own.
507
-
Any error from interactions will trigger `CommandError`. That includes context menus.
557
+
Any error from any command will trigger `CommandError` - note that this includes errors from context menus and (if enabled) prefixed commands.
508
558
509
559
In this example, we are logging the error and responding to the interaction if not done so yet:
510
560
```python
511
561
import traceback
512
562
from interactions.api.events import CommandError
513
563
514
-
@listen(CommandError, disable_default_listeners=True)# tell the dispatcher that this replaces the default listener
There also is `CommandCompletion` which you can overwrite too. That fires on every interactions usage.
571
+
!!! warning
572
+
If you override the default error listener, you will need to handle all errors yourself. This *includes* errors typically shown to the user, such as cooldowns and check errors.
573
+
574
+
There also is `CommandCompletion` which you can listen into too. That fires on every interactions usage.
0 commit comments