option
option<
T,R,C>(type,config):Option<T,R, [C] extends [never] ?OptionValue[T] :C[keyofC]>
Defined in: option.ts:70
Declares one option of a slash command. The handler reads its value from c.options,
typed from type, and undefined when the option is not required.
A string, integer or number option also takes choices, keyed by the label Discord shows.
The user can pick only those, and the handler gets one of their values. A string option takes
minLength and maxLength, an integer or number option takes min and max, and a
channel option takes channelTypes, such as ['text', 'forum'].
Instead of fixed choices, a string, integer or number option can take autocomplete: a
function that gets what the user has typed so far as c.value and returns up to 25 suggestions,
as plain values or as { name, value }. If it throws, onError gets the error and Discord shows
no suggestions.
Type Parameters
Section titled “Type Parameters”T extends keyof OptionValue
R extends boolean = false
C extends Record<string, Choice<T>> = never
Parameters
Section titled “Parameters”T
The value type Discord asks the user for. user, channel and role give the full
object Discord sends with the command, not only its id.
config
Section titled “config”OptionConfig<T, R, C>
How Discord shows the option.
Returns
Section titled “Returns”Option<T, R, [C] extends [never] ? OptionValue[T] : C[keyof C]>
The option, for the options of command.
Example
Section titled “Example”option('integer', { description: 'How many dice', required: true, min: 1, max: 6 });option('string', { description: 'Color', choices: { Red: 'red', Blue: 'blue' } });