Skip to content

SlashOption

SlashOption

Represents an option for a slash command.

Kind: global class

new SlashOption([data])

Creates a new instance of the SlashOption class.

ParamTypeDefaultDescription
[data]ObjectThe data for the option.
[data.type]string | number”"String"“The type of the option.
[data.name]stringThe name of the option.
[data.name_localizations]ObjectThe localized names of the option.
[data.description]stringThe description of the option.
[data.description_localizations]ObjectThe localized descriptions of the option.
[data.required]booleanWhether the option is required or not.
[data.choices]Array.<Object>The choices for the option.
[data.channel_types]Array.<string>The channel types that the option can be used with.
[data.min_value]numberThe minimum value for the option.
[data.max_value]numberThe maximum value for the option.
[data.min_length]numberThe minimum length for the option.
[data.max_length]numberThe maximum length for the option.
[data.autocomplete]booleanWhether the option should be autocompleted or not.

slashOption.setType(type) ⇒ SlashOption

Sets the type of the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
typestring | numberThe type of the option.

slashOption.setName(name) ⇒ SlashOption

Sets the name of the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
namestringThe name of the option.

slashOption.setDescription(description) ⇒ SlashOption

Sets the description of the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
descriptionstringThe description of the option.

slashOption.setRequired(required) ⇒ SlashOption

Sets whether the option is required or not.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
requiredbooleanWhether the option is required or not.

slashOption.setDescriptionLocalizations(localizations) ⇒ SlashOption

Sets the localized descriptions of the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
localizationsObjectThe localized descriptions of the option.

slashOption.setNameLocalizations([localizations]) ⇒ SlashOption

Sets the localized names of the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
[localizations]ObjectThe localized names of the option.

slashOption.setChoices(…choices) ⇒ SlashOption

Sets the choices for the option.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
…choicesObject | Array.<Object>The choices for the option.

slashOption.setChannelTypes(…channelTypes) ⇒ SlashOption

Sets the channel types that the option can be used with.

Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.

ParamTypeDescription
…channelTypesstring | Array.<string>The channel types that the option can be used with.

slashOption.setMinValue(minValue) ⇒ SlashOption

Sets the minimum value allowed for the option.

Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.

ParamTypeDescription
minValuenumberThe minimum value.

slashOption.setMaxValue(maxValue) ⇒ SlashOption

Sets the maximum value allowed for the option.

Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.

ParamTypeDescription
maxValuenumberThe maximum value.

slashOption.setMinLength(minLength) ⇒ SlashOption

Sets the minimum length allowed for the option.

Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.

ParamTypeDescription
minLengthnumberThe minimum length.

slashOption.setMaxLength(maxLength) ⇒ SlashOption

Sets the maximum length allowed for the option.

Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.

ParamTypeDescription
maxLengthnumberThe maximum length.

slashOption.setAutocomplete(autocomplete) ⇒ SlashOption

Sets whether the option is autocompletable.

Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.

ParamTypeDescription
autocompletebooleanWhether the option is autocompletable.

slashOption.validation()

Validates the option data and throws an error if any data is invalid.

Kind: instance method of SlashOption
Throws:

  • RangeError - If option type is invalid, option name or description is empty, or length is greater than limit.
  • TypeError - If option name or description is not a string, or option required or autocomplete is not a boolean.

slashOption.toJSON() ⇒ Object

Returns a JSON representation of the SlashOption instance, after performing validation.

Kind: instance method of SlashOption
Returns: Object - JSON object with the following properties:

  • type: The type of option, either as a string or an OptionType enum value.
  • name: The name of the option.
  • name_localizations: An object containing localized names for the option.
  • description: A description of the option.
  • description_localizations: An object containing localized descriptions for the option.
  • required: A boolean indicating whether the option is required.
  • choices: An array of choice objects for the option, if applicable.
  • channel_types: An array of channel type objects for the option, if applicable.
  • min_value: The minimum value for the option, if applicable.
  • max_value: The maximum value for the option, if applicable.
  • max_length: The maximum length of the option, if applicable.
  • min_length: The minimum length of the option, if applicable.
  • autocomplete: A boolean indicating whether the option supports autocomplete.

SlashOption.transformChannelType(channelType) ⇒ number

Transforms a channel type string to its respective integer value.

Kind: static method of SlashOption
Returns: number - - The channel type integer value.

ParamTypeDescription
channelTypestringThe channel type string.

SlashOption.transformChoices(choices) ⇒ Object

Transforms the choices object to a format suitable for the API.

Kind: static method of SlashOption
Returns: Object - - The transformed choices object.

ParamTypeDescription
choicesObjectThe choices object.
[choices.name]stringThe name of the choice.
[choices.value]stringThe value of the choice.
[choices.nameLocalizations]Object.<string, string>The localized names of the choice.