Class OptionData
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.build.OptionData
-
- All Implemented Interfaces:
SerializableData
public class OptionData extends Object implements SerializableData
Builder for a Slash-Command option.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_CHOICE_NAME_LENGTHThe maximum length of the name of Command Option Choice namesstatic intMAX_CHOICE_VALUE_LENGTHThe maximum length aString valuefor a choice can be.static intMAX_CHOICESThe total amount ofchoicesyou can set.static intMAX_DESCRIPTION_LENGTHThe maximum length the description of an option can be.static intMAX_NAME_LENGTHThe maximum length the name of an option can be.static doubleMAX_POSITIVE_NUMBERThe highest positive amount Discord allows theNUMBERtype to be.static doubleMIN_NEGATIVE_NUMBERThe largest negative amount Discord allows theNUMBERtype to be.
-
Constructor Summary
Constructors Constructor Description OptionData(OptionType type, String name, String description)Create an option builder.OptionData(OptionType type, String name, String description, boolean isRequired)Create an option builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionDataaddChoice(String name, double value)Add a predefined choice for this option.OptionDataaddChoice(String name, int value)Add a predefined choice for this option.OptionDataaddChoice(String name, long value)Add a predefined choice for this option.OptionDataaddChoice(String name, String value)Add a predefined choice for this option.OptionDataaddChoices(Collection<? extends Command.Choice> choices)Adds up to 25 predefined choices for this option.OptionDataaddChoices(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.EnumSet<ChannelType>getChannelTypes()TheChannelTypesthis option is restricted to.List<Command.Choice>getChoices()The choices for this option.StringgetDescription()The description for this optionStringgetName()The name for this optionOptionTypegetType()TheOptionTypefor this optionbooleanisRequired()Whether this option is required.OptionDatasetChannelTypes(Collection<ChannelType> channelTypes)Configure theChannelTypesto restrict this option to.OptionDatasetChannelTypes(ChannelType... channelTypes)Configure theChannelTypesto restrict this option to.OptionDatasetDescription(String description)Configure the descriptionOptionDatasetName(String name)Configure the nameOptionDatasetRequired(boolean required)Configure whether the user must set this option.DataObjecttoData()SerializedDataObjectfor this object.
-
-
-
Field Detail
-
MAX_POSITIVE_NUMBER
public static final double MAX_POSITIVE_NUMBER
The highest positive amount Discord allows theNUMBERtype to be.- See Also:
- Constant Field Values
-
MIN_NEGATIVE_NUMBER
public static final double MIN_NEGATIVE_NUMBER
The largest negative amount Discord allows theNUMBERtype to be.- See Also:
- Constant Field Values
-
MAX_NAME_LENGTH
public static final int MAX_NAME_LENGTH
The maximum length the name of an option can be.- See Also:
- Constant Field Values
-
MAX_CHOICE_NAME_LENGTH
public static final int MAX_CHOICE_NAME_LENGTH
The maximum length of the name of Command Option Choice names- See Also:
- Constant Field Values
-
MAX_DESCRIPTION_LENGTH
public static final int MAX_DESCRIPTION_LENGTH
The maximum length the description of an option can be.- See Also:
- Constant Field Values
-
MAX_CHOICE_VALUE_LENGTH
public static final int MAX_CHOICE_VALUE_LENGTH
The maximum length aString valuefor a choice can be.- See Also:
- Constant Field Values
-
MAX_CHOICES
public static final int MAX_CHOICES
The total amount ofchoicesyou can set.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OptionData
public OptionData(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description)
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
-
-
Method Detail
-
getType
@Nonnull public OptionType getType()
TheOptionTypefor this option- Returns:
- The
OptionType
-
getDescription
@Nonnull public String 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
-
getChannelTypes
@Nonnull public EnumSet<ChannelType> getChannelTypes()
TheChannelTypesthis option is restricted to.
This is empty if the option is not of typeCHANNELor not restricted to specific types.- Returns:
EnumSetofChannelType
-
getChoices
@Nonnull public List<Command.Choice> 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:
addChoice(String, int),addChoice(String, long),addChoice(String, String)
-
setName
@Nonnull public OptionData setName(@Nonnull String name)
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
@Nonnull public OptionData setDescription(@Nonnull String description)
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
@Nonnull public OptionData setRequired(boolean required)
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
-
setChannelTypes
@Nonnull public OptionData setChannelTypes(@Nonnull ChannelType... channelTypes)
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
@Nonnull public OptionData setChannelTypes(@Nonnull Collection<ChannelType> channelTypes)
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
-
addChoice
@Nonnull public OptionData addChoice(@Nonnull String name, double value)
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
-
addChoice
@Nonnull public OptionData addChoice(@Nonnull String name, int value)
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 long- The amount of already set choices is less than
MAX_CHOICES - The
OptionTypeisOptionType.INTEGER
-
addChoice
@Nonnull public OptionData addChoice(@Nonnull String name, long value)
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
-
addChoice
@Nonnull public OptionData addChoice(@Nonnull String name, @Nonnull String value)
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
-
addChoices
@Nonnull public OptionData addChoices(@Nonnull Command.Choice... choices)
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
-
addChoices
@Nonnull public OptionData addChoices(@Nonnull Collection<? extends Command.Choice> choices)
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
-
toData
@Nonnull public DataObject toData()
Description copied from interface:SerializableDataSerializedDataObjectfor this object.- Specified by:
toDatain interfaceSerializableData- Returns:
DataObject
-
fromData
@Nonnull public static OptionData fromData(@Nonnull DataObject json)
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
-
-