SlashOption
Represents an option for a slash command.
Kind: global class
- SlashOption
- new SlashOption([data])
- instance
- .setType(type) ⇒
SlashOption - .setName(name) ⇒
SlashOption - .setDescription(description) ⇒
SlashOption - .setRequired(required) ⇒
SlashOption - .setDescriptionLocalizations(localizations) ⇒
SlashOption - .setNameLocalizations([localizations]) ⇒
SlashOption - .setChoices(…choices) ⇒
SlashOption - .setChannelTypes(…channelTypes) ⇒
SlashOption - .setMinValue(minValue) ⇒
SlashOption - .setMaxValue(maxValue) ⇒
SlashOption - .setMinLength(minLength) ⇒
SlashOption - .setMaxLength(maxLength) ⇒
SlashOption - .setAutocomplete(autocomplete) ⇒
SlashOption - .validation()
- .toJSON() ⇒
Object
- .setType(type) ⇒
- static
- .transformChannelType(channelType) ⇒
number - .transformChoices(choices) ⇒
Object
- .transformChannelType(channelType) ⇒
new SlashOption([data])
Section titled “new SlashOption([data])”Creates a new instance of the SlashOption class.
| Param | Type | Default | Description |
|---|---|---|---|
| [data] | Object | The data for the option. | |
| [data.type] | string | number | ”"String"“ | The type of the option. |
| [data.name] | string | The name of the option. | |
| [data.name_localizations] | Object | The localized names of the option. | |
| [data.description] | string | The description of the option. | |
| [data.description_localizations] | Object | The localized descriptions of the option. | |
| [data.required] | boolean | Whether 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] | number | The minimum value for the option. | |
| [data.max_value] | number | The maximum value for the option. | |
| [data.min_length] | number | The minimum length for the option. | |
| [data.max_length] | number | The maximum length for the option. | |
| [data.autocomplete] | boolean | Whether the option should be autocompleted or not. |
slashOption.setType(type) ⇒ SlashOption
Section titled “slashOption.setType(type) ⇒ SlashOption”Sets the type of the option.
Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.
| Param | Type | Description |
|---|---|---|
| type | string | number | The type of the option. |
slashOption.setName(name) ⇒ SlashOption
Section titled “slashOption.setName(name) ⇒ SlashOption”Sets the name of the option.
Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.
| Param | Type | Description |
|---|---|---|
| name | string | The name of the option. |
slashOption.setDescription(description) ⇒ SlashOption
Section titled “slashOption.setDescription(description) ⇒ SlashOption”Sets the description of the option.
Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.
| Param | Type | Description |
|---|---|---|
| description | string | The description of the option. |
slashOption.setRequired(required) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| required | boolean | Whether the option is required or not. |
slashOption.setDescriptionLocalizations(localizations) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| localizations | Object | The localized descriptions of the option. |
slashOption.setNameLocalizations([localizations]) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| [localizations] | Object | The localized names of the option. |
slashOption.setChoices(…choices) ⇒ SlashOption
Section titled “slashOption.setChoices(…choices) ⇒ SlashOption”Sets the choices for the option.
Kind: instance method of SlashOption
Returns: SlashOption - The updated instance of the SlashOption class.
| Param | Type | Description |
|---|---|---|
| …choices | Object | Array.<Object> | The choices for the option. |
slashOption.setChannelTypes(…channelTypes) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| …channelTypes | string | Array.<string> | The channel types that the option can be used with. |
slashOption.setMinValue(minValue) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| minValue | number | The minimum value. |
slashOption.setMaxValue(maxValue) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| maxValue | number | The maximum value. |
slashOption.setMinLength(minLength) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| minLength | number | The minimum length. |
slashOption.setMaxLength(maxLength) ⇒ SlashOption
Section titled “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.
| Param | Type | Description |
|---|---|---|
| maxLength | number | The maximum length. |
slashOption.setAutocomplete(autocomplete) ⇒ SlashOption
Section titled “slashOption.setAutocomplete(autocomplete) ⇒ SlashOption”Sets whether the option is autocompletable.
Kind: instance method of SlashOption
Returns: SlashOption - - The current instance of the SlashOption class.
| Param | Type | Description |
|---|---|---|
| autocomplete | boolean | Whether the option is autocompletable. |
slashOption.validation()
Section titled “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
Section titled “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
Section titled “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.
| Param | Type | Description |
|---|---|---|
| channelType | string | The channel type string. |
SlashOption.transformChoices(choices) ⇒ Object
Section titled “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.
| Param | Type | Description |
|---|---|---|
| choices | Object | The choices object. |
| [choices.name] | string | The name of the choice. |
| [choices.value] | string | The value of the choice. |
| [choices.nameLocalizations] | Object.<string, string> | The localized names of the choice. |