CommandOption

class CommandOption<TValue, TOptional, TKind>

Configures one slash-command option. The schema key becomes the handler argument name; use discordName only when Discord should receive a different option name.

Type parameters

  • TValue

  • TOptional – (extends boolean)

  • TKind – (extends string)

Properties

Property

Type

Description

kind

TKind

Methods

CommandOption.autocomplete(
provider: TValue extends string | number ? (context: { interaction: Interaction; value: TValue; }) => (TValue | AutocompleteChoice<TValue>)[] | Promise<(TValue | AutocompleteChoice<TValue>)[]> : never
) → CommandOption<TValue, TOptional, TKind>

Suggests values while the user types. The provider receives the current input as value and returns up to 25 suggestions; extra entries are dropped. Discord closes the request after 3 seconds, so answer from data you already have where possible. Cannot be combined with choices.

CommandOption.channelTypes(types: ChannelType[]) → CommandOption<TValue, TOptional, TKind>

Limits which channels Discord offers for a channel option.

channel: option.channel("Where to post").channelTypes([
  discord.ChannelType.GUILD_TEXT,
  discord.ChannelType.GUILD_ANNOUNCEMENT,
]),
CommandOption.choices(...choices: (TValue | OptionChoice<Extract<TValue, string | number>>)[]) → CommandOption<TValue, TOptional, TKind>

Restricts the option to fixed values. Pass plain values, or objects with a display name when the label should differ from the value. Discord allows at most 25 choices, and an option cannot have both choices and autocomplete.

CommandOption.discordName(name: string) → CommandOption<TValue, TOptional, TKind>

Sets the option name registered with Discord. By default the schema key is converted to kebab case (userId becomes user-id). Names must be 1-32 lowercase letters, numbers, hyphens, or underscores.

CommandOption.localizations(values: { description?: LocaleMap; name?: LocaleMap; }) → CommandOption<TValue, TOptional, TKind>

Localized option names and descriptions, keyed by Discord locale.

CommandOption.maxLength(value: number) → CommandOption<TValue, TOptional, TKind>

Maximum string length Discord accepts, from 1 to 6000.

CommandOption.maxValue(value: number) → CommandOption<TValue, TOptional, TKind>

Largest value Discord accepts for an integer or number option.

CommandOption.minLength(value: number) → CommandOption<TValue, TOptional, TKind>

Minimum string length Discord accepts, from 0 to 6000.

CommandOption.minValue(value: number) → CommandOption<TValue, TOptional, TKind>

Smallest value Discord accepts for an integer or number option.

CommandOption.optional() → CommandOption<TValue, true, TKind>

Makes this option optional. Its handler value becomes TValue | null.