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
Copy file name to clipboardExpand all lines: docs/src/Guides/03 Creating Commands.md
+58-60
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Creating Slash Commands
1
+
# Slash Commands
2
2
3
3
So you want to make a slash command (or interaction, as they are officially called), but don't know how to get started?
4
4
Then this is the right place for you.
@@ -107,7 +107,7 @@ For all of these, the "group" parts are optional, allowing you to do `/base comm
107
107
You cannot mix group subcommands and non-group subcommands into one base command - you must either use all group subcommands or normal subcommands.
108
108
109
109
110
-
## But I Need More Options
110
+
## Options
111
111
112
112
Interactions can also have options. There are a bunch of different [types of options](/interactions.py/API Reference/API Reference/models/Internal/application_commands/#interactions.models.internal.application_commands.OptionType):
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).
159
159
160
-
## Restricting Options
160
+
###Restricting Options
161
161
162
162
If you are using an `OptionType.CHANNEL` option, you can restrict the channel a user can choose by setting `channel_types`:
163
163
```python
164
-
@slash_command(name="my_command", ...)
164
+
from interactions import ChannelType, GuildText, OptionType, SlashContext, slash_command, slash_option
Be aware that the option `name` and the function parameter need to be the same (In this example both are `integer_option`).
210
212
211
213
212
-
## But I Want A Choice
214
+
## Option Choices
213
215
214
216
If your users ~~are dumb~~ constantly misspell specific strings, it might be wise to set up choices.
215
-
With choices, the user can no longer freely input whatever they want, instead, they must choose from a curated list.
217
+
With choices, the user can no longer freely input whatever they want, instead, they must choose from a pre-defined list.
216
218
217
-
To create a choice, simply fill `choices` in `@slash_option()`. An option can have up to 25 choices:
219
+
To create a choice, simply fill `choices` in `@slash_option()`. An option can have up to 25 choices. The name of a choice is what will be shown in the Discord client of the user, while the value is what the bot will receive in its callback. Both can be the same.
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).
237
239
238
-
## I Need More Than 25 Choices
240
+
## Autocomplete / More than 25 choices needed
239
241
240
-
Looks like you want autocomplete options. These dynamically show users choices based on their input.
242
+
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.
241
243
The downside is that you need to supply the choices on request, making this a bit more tricky to set up.
242
244
243
245
To use autocomplete options, set `autocomplete=True` in `@slash_option()`:
@@ -260,10 +262,10 @@ In there, you have three seconds to return whatever choices you want to the user
You are in luck. There are currently four different ways to create interactions, one does not need any decorators at all.
291
+
There are currently four different ways to define interactions, one does not need any decorators at all.
290
292
291
293
=== ":one: Multiple Decorators"
294
+
292
295
```python
293
296
@slash_command(name="my_command", description="My first command :)")
294
297
@slash_option(
@@ -302,6 +305,7 @@ You are in luck. There are currently four different ways to create interactions,
302
305
```
303
306
304
307
=== ":two: Single Decorator"
308
+
305
309
```python
306
310
from interactions import SlashCommandOption
307
311
@@ -322,6 +326,7 @@ You are in luck. There are currently four different ways to create interactions,
322
326
```
323
327
324
328
=== ":three: Function Annotations"
329
+
325
330
```python
326
331
from interactions import slash_int_option
327
332
@@ -331,6 +336,7 @@ You are in luck. There are currently four different ways to create interactions,
331
336
```
332
337
333
338
=== ":four: Manual Registration"
339
+
334
340
```python
335
341
from interactions import SlashCommandOption
336
342
@@ -353,34 +359,34 @@ You are in luck. There are currently four different ways to create interactions,
353
359
)
354
360
```
355
361
356
-
## I Don't Want My Friends Using My Commands
362
+
## Restrict commands using permissions
357
363
358
-
How rude.
364
+
It is possible to disable interactions (slash commands as well as context menus) for users that do not have a set of permissions.
359
365
360
-
Anyway, this is somewhat possible with command permissions.
361
-
While you cannot explicitly block / allow certain roles / members / channels to use your commands on the bot side, you can define default permissions which members need to have to use the command.
366
+
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.
362
367
363
-
However, these default permissions can be overwritten by server admins, so this system is not safe for stuff like owner only eval commands.
364
-
This system is designed to limit access to admin commands after a bot is added to a server, before admins have a chance to customise the permissions they want.
368
+
!!!warning Administrators
369
+
Remember that administrators of a Discord serverhave all permissions and therefore will always see the commands.
365
370
366
-
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][check-this-out].
371
+
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].
367
372
368
373
In this example, we will limit access to the command to members with the `MANAGE_EVENTS` and `MANAGE_THREADS` permissions.
369
374
There are two ways to define permissions.
370
375
371
376
=== ":one: Decorators"
372
-
```py
377
+
378
+
```python
373
379
from interactions import Permissions, slash_default_member_permission
The check will be checked for every command in the extension.
470
469
471
470
471
+
## Avoid redefining the same option everytime
472
472
473
-
## I Don't Want To Define The Same Option Every Time
474
-
475
-
If you are like me, you find yourself reusing options in different commands and having to redefine them every time which is both annoying and bad programming.
473
+
If you have multiple commands that all use the same option, it might be both annoying and bad programming to redefine it multiple times.
476
474
477
475
Luckily, you can simply make your own decorators that themselves call `@slash_option()`:
There also is `CommandCompletion` which you can overwrite too. That fires on every interactions usage.
519
517
520
-
## I Need A Custom Parameter Type
518
+
## Custom Parameter Type
521
519
522
520
If your bot is complex enough, you might find yourself wanting to use custom models in your commands.
523
521
524
-
To do this, you'll want to use a string option, and define a converter. Information on how to use converters can be found [on the converter page](/Guides/08 Converters).
522
+
To do this, you'll want to use a string option, and define a converter. Information on how to use converters can be found [on the converter page](../08 Converters).
525
523
526
-
## I Want To Make A Prefixed/Text Command Too
524
+
## Prefixed/Text Commands
527
525
528
-
You're in luck! You can use a hybrid command, which is a slash command that also gets converted to an equivalent prefixed command under the hood.
526
+
To use prefixed commands, instead of typing `/my_command`, you will need to type instead `!my_command`, provided that the prefix you set is `!`.
529
527
530
-
Hybrid commands are their own extension, and require [prefixed commands to set up beforehand](/interactions.py/Guides/26 Prefixed Commands). After that, use the `setup` function in the `hybrid_commands` extension in your main bot file.
528
+
Hybrid commands are are slash commands that also get converted to an equivalent prefixed command under the hood. They are their own extension, and require [prefixed commands to be set up beforehand](/interactions.py/Guides/26 Prefixed Commands). After that, use the `setup` function in the `hybrid_commands` extension in your main bot file.
531
529
532
530
Your setup can (but doesn't necessarily have to) look like this:
533
531
@@ -556,4 +554,4 @@ Suggesting you are using the default mention settings for your bot, you should b
556
554
As you can see, the only difference between hybrid commands and slash commands, from a developer perspective, is that they use `HybridContext`, which attempts
557
555
to seamlessly allow using the same context for slash and prefixed commands. You can always get the underlying context via `inner_context`, though.
558
556
559
-
Of course, keep in mind that support two different types of commands is hard - some features may not get represented well in prefixed commands, and autocomplete is not possible at all.
557
+
Of course, keep in mind that supporting two different types of commands is hard - some features may not get represented well in prefixed commands, and autocomplete is not possible at all.
0 commit comments