Class OptionData
java.lang.Object
net.dv8tion.jda.api.interactions.commands.build.OptionData
- All Implemented Interfaces:
SerializableData
Builder for a Slash-Command option.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum length of the name of Command Option Choice namesstatic final intThe maximum length aString valuefor a choice can be.static final intThe total amount ofchoicesyou can set.static final intThe maximum length the description of an option can be.static final intThe maximum length the name of an option can be.static final doubleThe highest positive amount Discord allows theNUMBERtype to be.static final intThe maximum length for aString option.static final doubleThe largest negative amount Discord allows theNUMBERtype to be. -
Constructor Summary
ConstructorsConstructorDescriptionOptionData(OptionType type, String name, String description) Create an option builder.OptionData(OptionType type, String name, String description, boolean isRequired) Create an option builder.OptionData(OptionType type, String name, String description, boolean isRequired, boolean isAutoComplete) Create an option builder. -
Method Summary
Modifier and TypeMethodDescriptionAdd a predefined choice for this option.Add a predefined choice for this option.Add a predefined choice for this option.addChoices(Collection<? extends Command.Choice> choices) Adds up to 25 predefined choices for this option.addChoices(Command.Choice... choices) Adds up to 25 predefined choices for this option.static OptionDatafromData(DataObject json) Parses the provided serialization back into an OptionData instance.static OptionDatafromOption(Command.Option option) Converts the providedCommand.Optioninto a OptionData instance.TheChannelTypesthis option is restricted to.@Unmodifiable List<Command.Choice>The choices for this option.The description for this optionThe localizations of this option's description forvarious languages.The maximum length for strings which can be provided for this option.The maximum value which can be provided for this option.The minimum length for strings which can be provided for this option.The minimum value which can be provided for this option.getName()The name for this optionThe localizations of this option's name forvarious languages.getType()TheOptionTypefor this optionbooleanWhether this option supports auto-complete interactions viaCommandAutoCompleteInteractionEvent.booleanWhether this option is required.setAutoComplete(boolean autoComplete) Configure whether this option should support auto-complete interactions viaCommandAutoCompleteInteractionEvent.setChannelTypes(Collection<ChannelType> channelTypes) Configure theChannelTypesto restrict this option to.setChannelTypes(ChannelType... channelTypes) Configure theChannelTypesto restrict this option to.setDescription(String description) Configure the descriptionsetDescriptionLocalization(DiscordLocale locale, String description) Sets alanguage-specificlocalization of this option's description.Sets multiplelanguage-specificlocalizations of this option's description.setMaxLength(int maxLength) Configure the maximum length for strings which can be provided for this option.setMaxValue(double value) Configure the maximal value which can be provided for this option.setMaxValue(long value) Configure the maximal value which can be provided for this option.setMinLength(int minLength) Configure the minimum length for strings which can be provided for this option.setMinValue(double value) Configure the minimal value which can be provided for this option.setMinValue(long value) Configure the minimal value which can be provided for this option.Configure the namesetNameLocalization(DiscordLocale locale, String name) Sets alanguage-specificlocalization of this option's name.Sets multiplelanguage-specificlocalizations of this option's name.setRequired(boolean required) Configure whether the user must set this option.setRequiredLength(int minLength, int maxLength) Configure the minimum and maximum length for strings which can be provided for this option.setRequiredRange(double minValue, double maxValue) Configure the minimal and maximal value which can be provided for this option.setRequiredRange(long minValue, long maxValue) Configure the minimal and maximal value which can be provided for this option.toData()SerializedDataObjectfor this object.
-
Field Details
-
MAX_POSITIVE_NUMBER
public static final double MAX_POSITIVE_NUMBERThe highest positive amount Discord allows theNUMBERtype to be.- See Also:
-
MIN_NEGATIVE_NUMBER
public static final double MIN_NEGATIVE_NUMBERThe largest negative amount Discord allows theNUMBERtype to be.- See Also:
-
MAX_NAME_LENGTH
public static final int MAX_NAME_LENGTHThe maximum length the name of an option can be.- See Also:
-
MAX_CHOICE_NAME_LENGTH
public static final int MAX_CHOICE_NAME_LENGTHThe maximum length of the name of Command Option Choice names- See Also:
-
MAX_DESCRIPTION_LENGTH
public static final int MAX_DESCRIPTION_LENGTHThe maximum length the description of an option can be.- See Also:
-
MAX_CHOICE_VALUE_LENGTH
public static final int MAX_CHOICE_VALUE_LENGTHThe maximum length aString valuefor a choice can be.- See Also:
-
MAX_CHOICES
public static final int MAX_CHOICESThe total amount ofchoicesyou can set.- See Also:
-
MAX_STRING_OPTION_LENGTH
public static final int MAX_STRING_OPTION_LENGTHThe maximum length for aString option.- See Also:
-
-
Constructor Details
-
OptionData
Create an option builder.
This option is notrequiredby default.- Parameters:
type- TheOptionTypename- The option name, up to 32 alphanumeric (with dash) lowercase characters, as defined byMAX_NAME_LENGTHdescription- The option description, up to 100 characters, as defined byMAX_DESCRIPTION_LENGTH- Throws:
IllegalArgumentException-
-
OptionData
public OptionData(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean isRequired) Create an option builder.- Parameters:
type- TheOptionTypename- The option name, up to 32 alphanumeric (with dash) lowercase characters, as defined byMAX_NAME_LENGTHdescription- The option description, up to 100 characters, as defined byMAX_DESCRIPTION_LENGTHisRequired-True, if this option is required- Throws:
IllegalArgumentException-
-
OptionData
public OptionData(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean isRequired, boolean isAutoComplete) Create an option builder.- Parameters:
type- TheOptionTypename- The option name, up to 32 alphanumeric (with dash) lowercase characters, as defined byMAX_NAME_LENGTHdescription- The option description, up to 100 characters, as defined byMAX_DESCRIPTION_LENGTHisRequired-True, if this option is requiredisAutoComplete- True, if auto-complete should be supported (requiresOptionType.canSupportChoices())- Throws:
IllegalArgumentException-- If
typeis null - If
typeisUNKNOWN,SUB_COMMAND, orSUB_COMMAND_GROUP - If
nameis not alphanumeric (with dash), lowercase and between 1 and 32 characters long - If
descriptionis not between 1 and 100 characters long - If
OptionType.canSupportChoices()is false andisAutoCompleteis true
- If
-
-
Method Details
-
getType
TheOptionTypefor this option- Returns:
- The
OptionType
-
getName
The name for this option- Returns:
- The name
-
getNameLocalizations
The localizations of this option's name forvarious languages.- Returns:
- The
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized name
-
getDescription
The description for this option- Returns:
- The description
-
getDescriptionLocalizations
The localizations of this option's description forvarious languages.- Returns:
- The
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized description
-
isRequired
public boolean isRequired()Whether this option is required.
This can be configured withsetRequired(boolean).Required options must always be set by the command invocation.
- Returns:
- True, if this option is required
-
isAutoComplete
public boolean isAutoComplete()Whether this option supports auto-complete interactions viaCommandAutoCompleteInteractionEvent.- Returns:
- True, if this option supports auto-complete
-
getChannelTypes
TheChannelTypesthis option is restricted to.
This is empty if the option is not of typeCHANNELor not restricted to specific types.- Returns:
EnumSetofChannelType
-
getMinValue
The minimum value which can be provided for this option.
This returnsnullif the value is not set or if the option is not of typeINTEGERorNUMBER.- Returns:
- The minimum value for this option
-
getMaxValue
The maximum value which can be provided for this option.
This returnsnullif the value is not set or if the option is not of typeINTEGERorNUMBER.- Returns:
- The maximum value for this option
-
getMinLength
The minimum length for strings which can be provided for this option.
This returnsnullif the value is not set or if the option is not of typeSTRING.- Returns:
- The minimum length for strings for this option or
null
-
getMaxLength
The maximum length for strings which can be provided for this option.
This returnsnullif the value is not set or if the option is not of typeSTRING.- Returns:
- The maximum length for strings for this option or
null
-
getChoices
The choices for this option.
This is empty by default and can only be configured for specific option types.- Returns:
- Immutable list of
Choices - See Also:
-
setName
Configure the name- Parameters:
name- The lowercase alphanumeric (with dash) name,1-32 characters long- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException- If the name is null, empty, not alphanumeric, or not between 1-32 characters long, as defined byMAX_NAME_LENGTH
-
setNameLocalization
Sets alanguage-specificlocalization of this option's name.- Parameters:
locale- The locale to associate the translated name withname- The translated name to put- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the locale is null
- If the name is null
- If the locale is
DiscordLocale.UNKNOWN - If the name does not pass the corresponding
name check
-
setNameLocalizations
Sets multiplelanguage-specificlocalizations of this option's name.- Parameters:
map- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the map is null
- If the map contains an
DiscordLocale.UNKNOWNkey - If the map contains a name which does not pass the corresponding
name check
-
setDescription
Configure the description- Parameters:
description- The description, 1-100 characters, as defined byMAX_DESCRIPTION_LENGTH- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException- If the name is null, empty, or longer than 100, as defined byMAX_DESCRIPTION_LENGTH
-
setDescriptionLocalization
@Nonnull public OptionData setDescriptionLocalization(@Nonnull DiscordLocale locale, @Nonnull String description) Sets alanguage-specificlocalization of this option's description.- Parameters:
locale- The locale to associate the translated description withdescription- The translated description to put- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the locale is null
- If the description is null
- If the locale is
DiscordLocale.UNKNOWN - If the description does not pass the corresponding
description check
-
setDescriptionLocalizations
Sets multiplelanguage-specificlocalizations of this option's description.- Parameters:
map- The map from which to transfer the translated descriptions- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the map is null
- If the map contains an
DiscordLocale.UNKNOWNkey - If the map contains a description which does not pass the corresponding
description check
-
setRequired
Configure whether the user must set this option.
Required options must always be filled out when using the command.- Parameters:
required- True, if this option is required- Returns:
- The OptionData instance, for chaining
-
setAutoComplete
Configure whether this option should support auto-complete interactions viaCommandAutoCompleteInteractionEvent.This is only supported for options which support choices. See
OptionType.canSupportChoices().- Parameters:
autoComplete- True, if auto-complete should be supported- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalStateException- If this option is already configured to use choices or the option type does not support auto-complete
-
setChannelTypes
Configure theChannelTypesto restrict this option to. This only applies to options of typeCHANNEL.- Parameters:
channelTypes- TheChannelTypesto restrict this option to or empty array to accept allChannelTypes- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notCHANNEL - If
channelTypescontainnull - If
channelTypescontains non-guild channels
- If
-
setChannelTypes
Configure theChannelTypesto restrict this option to. This only applies to options of typeCHANNEL.- Parameters:
channelTypes- TheChannelTypesto restrict this option to or empty collection to accept allChannelTypes- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notCHANNEL - If
channelTypesis null - If
channelTypescontainnull - If
channelTypescontains non-guild channels
- If
-
setMinValue
Configure the minimal value which can be provided for this option.- Parameters:
value- The minimal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notINTEGERorNUMBER - If
valueis less thanMIN_NEGATIVE_NUMBER
- If
-
setMinValue
Configure the minimal value which can be provided for this option.- Parameters:
value- The minimal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notNUMBER - If
valueis less thanMIN_NEGATIVE_NUMBER
- If
-
setMaxValue
Configure the maximal value which can be provided for this option.- Parameters:
value- The maximal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notINTEGERorNUMBER - If
valueis greater thanMAX_POSITIVE_NUMBER
- If
-
setMaxValue
Configure the maximal value which can be provided for this option.- Parameters:
value- The maximal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notNUMBER - If
valueis greater thanMAX_POSITIVE_NUMBER
- If
-
setRequiredRange
Configure the minimal and maximal value which can be provided for this option.- Parameters:
minValue- The minimal value which can be provided for this option.maxValue- The maximal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notINTEGERorNUMBER - If
minValueis less than or not equal toMIN_NEGATIVE_NUMBER - If
maxValueis greater thanMAX_POSITIVE_NUMBER
- If
-
setRequiredRange
Configure the minimal and maximal value which can be provided for this option.- Parameters:
minValue- The minimal value which can be provided for this option.maxValue- The maximal value which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notNUMBER - If
minValueis less than or not equal toMIN_NEGATIVE_NUMBER - If
maxValueis greater thanMAX_POSITIVE_NUMBER
- If
-
setMinLength
Configure the minimum length for strings which can be provided for this option.- Parameters:
minLength- The minimum length for strings which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notSTRING - If
minLengthis not positive
- If
-
setMaxLength
Configure the maximum length for strings which can be provided for this option.- Parameters:
maxLength- The maximum length for strings which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notSTRING - If
maxLengthis not positive or greater than 6000
- If
-
setRequiredLength
Configure the minimum and maximum length for strings which can be provided for this option.- Parameters:
minLength- The minimum length for strings which can be provided for this option.maxLength- The maximum length for strings which can be provided for this option.- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
type of this optionis notSTRING - If
minLengthis greater thanmaxLength
- If
-
addChoice
Add a predefined choice for this option.
The user can only provide one of the choices and cannot specify any other value.- Parameters:
name- The name used in the client, up to 100 characters long, as defined byMAX_CHOICE_NAME_LENGTHvalue- The value received inOptionMapping- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
nameis null, empty, or greater than 100 characters long - If
valueis less thanMIN_NEGATIVE_NUMBERor greater thanMAX_POSITIVE_NUMBER - If adding this choice would exceed 25 choices, as defined by
MAX_CHOICES - If the
OptionTypeis notOptionType.NUMBER - If the option is auto-complete enabled
- If
-
addChoice
Add a predefined choice for this option.
The user can only provide one of the choices and cannot specify any other value.- Parameters:
name- The name used in the clientvalue- The value received inOptionMapping- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
nameis null, empty, or greater than 100 characters long - If
valueis less thanMIN_NEGATIVE_NUMBERor greater thanMAX_POSITIVE_NUMBER - If adding this choice would exceed 25 choices, as defined by
MAX_CHOICES - If the
OptionTypeis notOptionType.INTEGER - If the option is auto-complete enabled
- If
-
addChoice
Add a predefined choice for this option.
The user can only provide one of the choices and cannot specify any other value.- Parameters:
name- The name used in the clientvalue- The value received inOptionMapping- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If
nameis null, empty, or greater than 100 characters long - If
valueis less thanMIN_NEGATIVE_NUMBERor greater thanMAX_POSITIVE_NUMBER - If adding this choice would exceed 25 choices, as defined by
MAX_CHOICES - If the
OptionTypeis notOptionType.STRING - If the option is auto-complete enabled
- If
-
addChoices
Adds up to 25 predefined choices for this option.
The user can only provide one of the choices and cannot specify any other value.- Parameters:
choices- The choices to add- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If the
OptionTypedoes notsupport choices - If the provided
choicesare null - If the amount of
choicesprovided, when combined with the already set choices, would be greater than 25, as defined byMAX_CHOICES - If the
OptionTypeof the choices is not eitherOptionType.INTEGER,OptionType.STRINGorOptionType.NUMBER - If the option is auto-complete enabled
- If the
-
addChoices
Adds up to 25 predefined choices for this option.
The user can only provide one of the choices and cannot specify any other value.- Parameters:
choices- The choices to add- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException-- If the
OptionTypedoes notsupport choices - If the provided
choicescollection is null - If the provided
choicesare null - If the amount of
choicesprovided, when combined with the already set choices, would be greater than 25, as defined byMAX_CHOICES - If the
OptionTypeof the choices is not eitherOptionType.INTEGER,OptionType.STRINGorOptionType.NUMBER - If the option is auto-complete enabled
- If the
-
toData
Description copied from interface:SerializableDataSerializedDataObjectfor this object.- Specified by:
toDatain interfaceSerializableData- Returns:
DataObject
-
fromData
Parses the provided serialization back into an OptionData instance.
This is the reverse function fortoData().- Parameters:
json- The serializedDataObjectrepresenting the option- Returns:
- The parsed OptionData instance, which can be further configured through setters
- Throws:
ParsingException- If the serialized object is missing required fieldsIllegalArgumentException- If any of the values are failing the respective checks such as length
-
fromOption
Converts the providedCommand.Optioninto a OptionData instance.- Parameters:
option- The option to convert- Returns:
- An instance of OptionData
- Throws:
IllegalArgumentException- If null is provided or the option has illegal configuration
-