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.
-
-
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 OptionData
addChoice(String name, int value)
Add a predefined choice for this option.OptionData
addChoice(String name, String value)
Add a predefined choice for this option.OptionData
addChoices(Collection<? extends Command.Choice> choices)
Adds up to 25 predefined choices for this option.OptionData
addChoices(Command.Choice... choices)
Adds up to 25 predefined choices for this option.static OptionData
fromData(DataObject json)
Parses the provided serialization back into an OptionData instance.List<Command.Choice>
getChoices()
The choices for this option.String
getDescription()
The description for this optionString
getName()
The name for this optionOptionType
getType()
TheOptionType
for this optionboolean
isRequired()
Whether this option is required.OptionData
setDescription(String description)
Configure the descriptionOptionData
setName(String name)
Configure the nameOptionData
setRequired(boolean required)
Configure whether the user must set this option.DataObject
toData()
SerializedDataObject
for this object.
-
-
-
Constructor Detail
-
OptionData
public OptionData(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description)
Create an option builder.
This option is notrequired
by default.- Parameters:
type
- TheOptionType
name
- The option name, 1-32 lowercase alphanumeric charactersdescription
- The option description, 1-100 characters- Throws:
IllegalArgumentException
- If any of the following requirements are not met- The name must be lowercase alphanumeric (with dash), 1-32 characters long
- The description must be 1-100 characters long
- The type must not be null
-
OptionData
public OptionData(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean isRequired)
Create an option builder.- Parameters:
type
- TheOptionType
name
- The option name, 1-32 lowercase alphanumeric charactersdescription
- The option description, 1-100 charactersisRequired
- True, if this option is required- Throws:
IllegalArgumentException
- If any of the following requirements are not met- The name must be lowercase alphanumeric (with dash), 1-32 characters long
- The description must be 1-100 characters long
- The type must not be null
-
-
Method Detail
-
getType
@Nonnull public OptionType getType()
TheOptionType
for 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
-
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, String)
-
setName
@Nonnull public OptionData setName(@Nonnull String name)
Configure the name- Parameters:
name
- The lowercase alphanumeric (with dash) name, 1-32 characters- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException
- If the name is null, not alphanumeric, or not between 1-32 characters
-
setDescription
@Nonnull public OptionData setDescription(@Nonnull String description)
Configure the description- Parameters:
description
- The description, 1-100 characters- Returns:
- The OptionData instance, for chaining
- Throws:
IllegalArgumentException
- If the name is null or not between 1-100 characters
-
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
-
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 the name is null, empty, or longer than 100 characters. Also thrown if this is not an option of typeOptionType.INTEGER
or more than 25 choices are provided.
-
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 the name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option of typeOptionType.STRING
or more than 25 choices are provided.
-
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 name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option type is incompatible with the choice type or more than 25 choices are provided.
-
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 name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option type is incompatible with the choice type or more than 25 choices are provided.
-
toData
@Nonnull public DataObject toData()
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in 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 serializedDataObject
representing 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
-
-