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 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.The choices for this option.The description for this optionThe maximum value which can be provided for this option.The minimum value which can be provided for this option.getName()The name for this optiongetType()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 descriptionsetMaxValue(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.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 namesetRequired(boolean required) Configure whether the user must set 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:
-
-
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- If any of the following checks fail
-
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- If any of the following checks fail
-
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 any of the following checks failtypeis not nullnameis alphanumeric (with dash), lowercase and between 1 and 32 characters longdescriptionis between 1 and 100 characters longOptionType.canSupportChoices()is false thenisAutoCompleteis also false
-
-
Method Details
-
getType
TheOptionTypefor this option- Returns:
- The
OptionType
-
getName
The name for this option- Returns:
- The name
-
getDescription
The description for this option- Returns:
- The 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
-
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
-
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 or larger thanMAX_DESCRIPTION_LENGTH
-
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 any of the following checks failtype of this optionisCHANNELchannelTypesdoesn't containnullchannelTypesonly contains guild channels
-
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 any of the following checks failtype of this optionisCHANNELchannelTypesis not nullchannelTypesdoesn't containnullchannelTypesonly contains guild channels
-
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 any of the following checks failtype of this optionisINTEGERorNUMBERvalueis larger than or equal toMIN_NEGATIVE_NUMBER
-
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 any of the following checks failtype of this optionisNUMBERvalueis larger than or equal toMIN_NEGATIVE_NUMBER
-
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 any of the following checks failtype of this optionisINTEGERorNUMBERvalueis lower than or equal toMAX_POSITIVE_NUMBER
-
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 any of the following checks failtype of this optionisNUMBERvalueis lower than or equal toMAX_POSITIVE_NUMBER
-
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 any of the following checks failtype of this optionisINTEGERorNUMBERminValueis larger than or equal toMIN_NEGATIVE_NUMBERmaxValueis lower than or equal toMAX_POSITIVE_NUMBER
-
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 any of the following checks failtype of this optionisNUMBERminValueis larger than or equal toMIN_NEGATIVE_NUMBERmaxValueis lower than or equal toMAX_POSITIVE_NUMBER
-
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 any of the following checks failnameis not null, empty and less or equal to 100 characters longvalueis not less thanMIN_NEGATIVE_NUMBERand not larger thanMAX_POSITIVE_NUMBER- The amount of already set choices is less than
MAX_CHOICES - The
OptionTypeisOptionType.NUMBER - The option is not auto-complete enabled
-
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 any of the following checks failnameis not null, empty and less or equal to 100 characters longvalueis not less thanMIN_NEGATIVE_NUMBERand not larger thanMAX_POSITIVE_NUMBER- The amount of already set choices is less than
MAX_CHOICES - The
OptionTypeisOptionType.INTEGER - The option is not auto-complete enabled
-
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 any of the following checks failnameis not null, empty and less or equal to 100 characters longvalueis not null, empty and less or equal to 100 characters long- The amount of already set choices is less than
MAX_CHOICES - The
OptionTypeisOptionType.STRING - The option is not auto-complete enabled
-
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 any of the following checks fail- The
OptionTypedoessupport choices - The provided
choicesare not null - The amount of
choicesprovided is smaller thanMAX_CHOICESwhen combined with already set choices - The
OptionTypeof the choices is eitherOptionType.INTEGER,OptionType.STRINGorOptionType.NUMBER - The option is not auto-complete enabled
- 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 any of the following checks fail- The
OptionTypedoessupport choices - The provided
choicesare not null - The amount of
choicesprovided is smaller thanMAX_CHOICESwhen combined with already set choices - The
OptionTypeof the choices is eitherOptionType.INTEGER,OptionType.STRINGorOptionType.NUMBER - The option is not auto-complete enabled
- 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
-