Class Command.Choice
java.lang.Object
net.dv8tion.jda.api.interactions.commands.Command.Choice
- Enclosing interface:
- Command
Predefined choice used for options.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum length the name of a choice can be.static final int
The maximum length theSTRING
value of a choice can be. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
double
The value of this choice.long
The value of this choice.The value of this choice.getName()
The readable name of this choice.The localizations of this choice's name forvarious languages
.getType()
TheOptionType
this choice is forint
hashCode()
Configure the choice namesetNameLocalization
(DiscordLocale locale, String name) Sets the name localizations of this choice.Sets the name localizations of this choice.toData
(OptionType optionType) toString()
-
Field Details
-
MAX_NAME_LENGTH
public static final int MAX_NAME_LENGTHThe maximum length the name of a choice can be.- See Also:
-
MAX_STRING_VALUE_LENGTH
public static final int MAX_STRING_VALUE_LENGTHThe maximum length theSTRING
value of a choice can be.- See Also:
-
-
Constructor Details
-
Choice
Create a Choice tuple- Parameters:
name
- The display name of this choice, must be less than 100 charactersvalue
- The integer value you receive in a command option- Throws:
IllegalArgumentException
- If the name is null, empty, or not between 1-100 characters long, as defined byMAX_NAME_LENGTH
-
Choice
Create a Choice tuple- Parameters:
name
- The display name of this choice, must be less than 100 charactersvalue
- The double value you receive in a command option- Throws:
IllegalArgumentException
- If the name is null, empty, or not between 1-100 characters long, as defined byMAX_NAME_LENGTH
-
Choice
Create a Choice tuple- Parameters:
name
- The display name of this choice, must be less than 100 charactersvalue
- The string value you receive in a command option- Throws:
IllegalArgumentException
-- If the name is null, empty, or not between 1-100 characters long,
as defined by
MAX_NAME_LENGTH
- If the value is null or longer than 100 characters long,
as defined by
MAX_STRING_VALUE_LENGTH
- If the name is null, empty, or not between 1-100 characters long,
as defined by
-
Choice
Create a Choice tuple- Parameters:
json
- The serialized choice instance with name and value mapping- Throws:
IllegalArgumentException
- If null is providedParsingException
- If the data is not formatted correctly or missing required parameters
-
-
Method Details
-
getName
The readable name of this choice.
This is shown to the user in the official client.- Returns:
- The choice name
-
setName
Configure the choice name- Parameters:
name
- The choice name,1-100 characters long
- Returns:
- The Choice instance, for chaining
- Throws:
IllegalArgumentException
- If the name is null, empty, or not between 1-100 characters long, as defined byMAX_NAME_LENGTH
-
getNameLocalizations
The localizations of this choice's name forvarious languages
.- Returns:
- The
LocalizationMap
containing the mapping fromDiscordLocale
to the localized name
-
setNameLocalization
@Nonnull public Command.Choice setNameLocalization(@Nonnull DiscordLocale locale, @Nonnull String name) Sets the name localizations of this choice.- 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 the name localizations of this choice.- 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.UNKNOWN
key - If the map contains a name which does not pass the corresponding
name check
-
getAsDouble
public double getAsDouble()The value of this choice.- Returns:
- The double value, or NaN if this is not a numeric choice value
-
getAsLong
public long getAsLong()The value of this choice.- Returns:
- The long value
-
getAsString
The value of this choice.- Returns:
- The String value
-
getType
TheOptionType
this choice is for- Returns:
- The option type of this choice
-
hashCode
public int hashCode() -
equals
-
toString
-
toData
-