Skip to content

CommandOptionBuilder

CommandOptionBuilder is used to construct options for a Discord application command, including type, name, description, and choices.

Usage:

local option = CommandOptionBuilder.new()
:setType(CommandOptionBuilder.Type.String)
:setName("example_option")
:setDescription("This is an example option.")
:setRequired(true)
:addChoice("Choice 1", "value1")
:addChoice("Choice 2", "value2")

Properties

Type

CommandOptionBuilder.Type  :: table

An enumeration of option types.

  • SubCommand: 1
  • SubCommandGroup: 2
  • String: 3
  • Integer: 4
  • Boolean: 5
  • User: 6
  • Channel: 7
  • Role: 8
  • Mentionable: 9
  • Number: 10
  • Attachment: 11

ChannelType

CommandOptionBuilder.ChannelType  :: table

An enumeration of channel types.

  • GuildText: 0
  • DirectMessage: 1
  • GuildVoice: 2
  • GroupDirectMessage: 3
  • GuildCategory: 4
  • GuildAnnouncement: 5
  • AnnouncementThread: 10
  • PublicThread: 11
  • PrivateThread: 12
  • GuildStageVoice: 13
  • GuildDirectory: 14
  • GuildForum: 15

Methods

setType

CommandOptionBuilder : setType (

     optionType: number
)  -> Builders.CommandOptionBuilder

Sets the type of the option.

setName

CommandOptionBuilder : setName (

     optionName: string
)  -> Builders.CommandOptionBuilder

Sets the name of the option.

setLocalization

CommandOptionBuilder : setLocalization (

     localizationCode: string
)  -> Builders.CommandOptionBuilder

Sets the localization code for the option.

setDescription

CommandOptionBuilder : setDescription (

     optionDescription: string
)  -> Builders.CommandOptionBuilder

Sets the description of the option.

setRequired

CommandOptionBuilder : setRequired (

     isRequired: boolean
)  -> Builders.CommandOptionBuilder

Sets whether the option is required.

setChannelTypes

CommandOptionBuilder : setChannelTypes (

     channelTypes: ...
)  -> Builders.CommandOptionBuilder

Sets the channel types for the option.

setMinValue

CommandOptionBuilder : setMinValue (

     minValue: number
)  -> Builders.CommandOptionBuilder

Sets the minimum value for the option.

setMaxValue

CommandOptionBuilder : setMaxValue (

     maxValue: number
)  -> Builders.CommandOptionBuilder

Sets the maximum value for the option.

setMinLength

CommandOptionBuilder : setMinLength (

     minLength: number
)  -> Builders.CommandOptionBuilder

Sets the minimum length for the option.

setMaxLength

CommandOptionBuilder : setMaxLength (

     maxLength: number
)  -> Builders.CommandOptionBuilder

Sets the maximum length for the option.

setAutocompleteEnabled

CommandOptionBuilder : setAutocompleteEnabled (

     autocomplete: boolean
)  -> Builders.CommandOptionBuilder

Sets whether autocomplete is enabled for the option.

addOption

CommandOptionBuilder : addOption (

     commandOption: CommandOptionBuilder
)  -> Builders.CommandOptionBuilder

Adds a sub-option to the option.

addChoice

CommandOptionBuilder : addChoice (

     choiceName: string
     choiceValue: any
)  -> Builders.CommandOptionBuilder

Adds a choice to the option.

toPayloadObject

CommandOptionBuilder : toPayloadObject ()  -> Network.Resolvable

Converts the option to a JSON object that can be sent to the Discord API.

Functions

new

CommandOptionBuilder . new ()  -> ()

Creates a new instance of CommandOptionBuilder.