Skip to content

option

option<T, R, C>(type, config): Option<T, R, [C] extends [never] ? OptionValue[T] : C[keyof C]>

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.

T extends keyof OptionValue

R extends boolean = false

C extends Record<string, Choice<T>> = never

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.

OptionConfig<T, R, C>

How Discord shows the option.

Option<T, R, [C] extends [never] ? OptionValue[T] : C[keyof C]>

The option, for the options of command.

option('integer', { description: 'How many dice', required: true, min: 1, max: 6 });
option('string', { description: 'Color', choices: { Red: 'red', Blue: 'blue' } });