CommandOptionsBuilder class

const commandOption = new CommandOptionsBuilder(data?: object);

constructor

The constructor provides one optional argument, which is an object which provides the data for the Command Options Builder.

The object may contain the following information:

  • name: The name of the command option you want to create.

  • description: A description of what the command option does.

  • required: A boolean which defines whether the option is required to fill in or not.

  • choices: An array with raw data of the command option choices which users can choose between in the slash command.

  • channelTypes: An array with the channel types as a number a user will get when the user has to fill in a channel option.

  • type: The option type a user has as a number.

  • minValue: A number for when the option type is a number with the minimum number a user should provide.

  • maxValue: A number for when the option type is a number with the maximum number a user may provide.

  • minLength: The minimum length of a string when the option type is a string.

  • maxLength: The maximum length of a string when the option type is a string.

ArgumentDescription

data

An object with the data to create the Command Options Builder from. The data which can be added is mentioned above.

Properties

name

The name of the command option which was set with the setName function.

description

The description of the command option which was set with the setDescription function.

required

A boolean which defines whether it is required or not to fill the command option in and was set with the setRequired function.

choices

An array with the command option choices converted to an object to make it a valid Discord API object, that have been set with the addChoices function.

channelTypes

An array with the allowed channel types for when the command option type is a channel, that have been set with the addChannelTypes function.

type

A number which defines what the command option type is and has been set with the setOptionType function.

minValue

The minimum number or integer that should be given when the command option type is a number or integer and has been set with the setMinValue function.

maxValue

The maximum number or integer that should be given when the command option type is a number or integer and has been set with the setMaxValue function.

minLength

The minimum length of the string that should be given when the command option type is a string and has been set with the setMinLength function.

maxLength

The maxmimum length of the string that should be given when the command option type is a string and has been set with the setMaxLength function.

Functions

setOptionType

commandOption.setOptionType(type: number) : CommandOptionsBuilder;

Sets the type for the command and returns the same CommandOptionsBuilder class so you don't have to declare it everytime again. This is required to create a command option. The available types can be found on the CommandOptionTypes page.

ArgumentDescription

type

A number which represents the type the option should have. The available types can be found on the CommandOptionTypes page.

setName

commandOption.setName(name: string) : CommandOptionsBuilder;

Sets the name for the command and returns the same CommandOptionsBuilder class so you don't have to declare it everytime again. This is required to create a command option.

ArgumentDescription

name

The name of the command option which is visible to the users using the command.

setDescription

commandOption.setDescription(description: string) : CommandOptionsBuilder;

Sets the description for the command and returns the same CommandOptionsBuilder class so you don't have to declare it everytime again. This is required to create a command option.

ArgumentDescription

description

The description of the command option which tells what the command option does and is visible to the users using the command.

setRequired

commandOption.setRequired(required?: boolean) : CommandOptionsBuilder;

Defines whether the command option is required for users using the command to fill in or not and returns the same CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

required

A boolean which defines whether the command option should be required to fill in or not.

addChoices

commandOption.addChoices(...choices: [CommandOptionChoiceBuilder]) : CommandOptionsBuilder;

Adds pre-made choices a user can choose between when using the command option and returns the same CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

choices

An array of CommandOptionChoiceBuilder classes or a CommandOptionChoiceBuilder class which defines the choice(s) a user can choose between when using the command.

addOptions

commandBuilder.addOptions(...options: [CommandOptionsBuilder]) : CommandBuilder;

Adds options to the command which users can fill in in case the parent CommandOptionsBuilder is a sub command. The function returns the same CommandOptionsBuilder class so you don't have to declare it everytime again. The options will be returned to the addon once the user executes the command.

addChannelTypes

commandOption.addChannelTypes(...channelTypes: [number]) : CommandOptionsBuilder;

Makes sure when the command option is a channel option type that only the channel types which are given in the addChannelTypes will be shown and not any other channel types. The function returns the CommandOptionsBuilder class so you don't have to declare it everytime again. The available types can be found on the ChannelTypes page.

ArgumentDescription

channelTypes

An array of channelTypes or a channelType as a number which defines which channel types can be chosen from when using the command option if the command option is a channel command option. The available types can be found on the ChannelTypes page.

setMinValue

commandOption.setMinValue(min: number) : CommandOptionsBuilder;

Sets the minimum number or integer which a user should give when the command option type is a number or integer and returns the CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

min

The minimum value the user should give when the command option type is a number or integer.

setMaxValue

commandOption.setMaxValue(max: number) : CommandOptionsBuilder;

Sets the maximum number or integer which a user may give when the command option type is a number or integer and returns the CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

max

The maximum value the user may give when the command option type is a number or integer.

setMinLength

commandOption.setMinLength(min: number) : CommandOptionsBuilder;

Sets the minimum length of the string which a user should give when the command option type is a string and returns the CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

min

The minimum length of a string which a user should give when the command option type is a string.

setMaxLength

commandOption.setMaxLength(max: number) : CommandOptionsBuilder;

Sets the maximum length of the string which a user should give when the command option type is a string and returns the CommandOptionsBuilder class so you don't have to declare it everytime again.

ArgumentDescription

max

The maximum length of a string which a user should give when the command option type is a string.

toJSON

commandOption.toJSON() : object;

Converts the CommandBuilder to an object to make it a valid object for the Discord API.

{
    name: string;
    description: string;
    required: boolean;
    choices: [object];
    options: undefined;
    channel_types: [number];
    type: number;
    min_value?: number;
    max_value?: number;
    min_length?: number;
    max_length?: number;
}

Last updated