run receives their values already typed: you never write a type.
src/commands/mod/ban.ts
target, reason and days in that order, and your editor knows that options.target is a User and that options.reason may be missing.
Every field of every kind of option is in the reference.
Declaring an option
The key is the name of the option, the value says what it is. Every option has atype and a description (1 to 100 characters, shown under its name):
Names follow the rules of Discord: lowercase letters, digits,
- and _, 32 characters at most. A command has 25 options at most.
Required or optional
An option is optional unless it saysrequired: true. In run, a required option is always there; an optional one may be undefined, and your editor reminds you:
src/commands/greet.ts
Choices
Withchoices, the person picks in a list instead of typing, and the value is typed as one of the choices. A string, integer or number option can have between 1 and 25 choices:
src/commands/color.ts
string option are texts, those of an integer or number option are numbers; what is shown is 1 to 100 characters. The same choice can’t appear twice.
Autocomplete
When the values are not known in advance, or change (a song, a player, a ticket),autocomplete suggests them while the person types: Discord asks your bot every few keystrokes, and shows what your function returns under the option. The person may still type something else.
src/commands/play.ts
autocomplete has one function per option, by its name, for a string, integer or number option without choices. It receives:
It returns the suggestions (or a promise of them): a value, shown as is, or
{ name, value } to show a text and receive another value. A string option suggests texts, an integer or number option numbers. Discord shows 25 at most, in the order you return them, and waits 3 seconds: return quickly, your best matches first.
What the function returns is checked when it is sent. Too many suggestions are cut to 25, and a name over 100 characters is shortened, said once with ⚠. What can’t be fixed is an error, and nothing is suggested:
Limits on what is typed
A text can be given a length, a number a range:
Discord refuses what is outside before the command even reaches your bot. For an
integer option, min, max and the choices are whole numbers.
Channels of some kinds only
channelTypes says which kinds of channels can be picked. By default, all of them:
src/commands/announce.ts
ChannelType. What run receives is still a Channel: check its kind with isTextBased() or isVoice() before using what only that kind has.
What is checked
Everything an option declares is checked when the file loads, against the limits of Discord. A mistake is explained in your terminal before Discord refuses it, with the file in front:A name Discord refuses
A name Discord refuses
A type that does not exist
A type that does not exist
A field the type does not have
A field the type does not have
A description missing or too long
A description missing or too long
Too many options
Too many options
Choices
Choices
A range that can never be filled in
A range that can never be filled in
Channel types
Channel types
Autocomplete
Autocomplete
command() only accept what exists.
Answering
Reply, defer, edit, follow up.
Translations
Options and choices in the language of each person.