Class SelectOption
java.lang.Object
net.dv8tion.jda.api.interactions.components.selections.SelectOption
- All Implemented Interfaces:
SerializableData
One of the possible options provided in a
SelectMenu
.-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum length a select option description can havestatic final int
The maximum length a select option label can havestatic final int
The maximum length a select option value can have -
Method Summary
Modifier and TypeMethodDescriptionstatic SelectOption
fromData
(DataObject data) Inverse function fortoData()
which parses the serialized option dataThe current description for this option.getEmoji()
The emoji attached to this option which is shown next to the option in the select menugetLabel()
The current option label which would be shown to the user in the client.getValue()
The current option value which is used to identify the selected options inSelectMenuInteraction.getValues()
.boolean
Whether this option is selected by defaultstatic SelectOption
Creates a new SelectOption instance.toData()
SerializedDataObject
for this object.withDefault
(boolean isDefault) Returns a copy of this select option with the changed default.withDescription
(String description) Returns a copy of this select option with the changed description of this option.Returns a copy of this select option with the changed emoji.Returns a copy of this select option with the changed label.Returns a copy of this select option with the changed value.
-
Field Details
-
LABEL_MAX_LENGTH
public static final int LABEL_MAX_LENGTHThe maximum length a select option label can have- See Also:
-
VALUE_MAX_LENGTH
public static final int VALUE_MAX_LENGTHThe maximum length a select option value can have- See Also:
-
DESCRIPTION_MAX_LENGTH
public static final int DESCRIPTION_MAX_LENGTHThe maximum length a select option description can have- See Also:
-
-
Method Details
-
of
@Nonnull @CheckReturnValue public static SelectOption of(@Nonnull String label, @Nonnull String value) Creates a new SelectOption instance.
You can further configure this with the various setters that return new instances.- Parameters:
label
- The label for the option, up to 100 characters, as defined byLABEL_MAX_LENGTH
value
- The value for the option used to indicate which option was selected withSelectMenuInteraction.getValues()
, up to 100 characters, as defined byVALUE_MAX_LENGTH
- Returns:
- The new select option instance
- Throws:
IllegalArgumentException
- If the null is provided, or any of the individual parameter requirements are violated.
-
withLabel
Returns a copy of this select option with the changed label.- Parameters:
label
- The label for the option, up to 100 characters, as defined byLABEL_MAX_LENGTH
- Returns:
- The new select option instance
- Throws:
IllegalArgumentException
- If the label is null, empty, or longer than 100 characters
-
withValue
Returns a copy of this select option with the changed value.- Parameters:
value
- The value for the option used to indicate which option was selected withSelectMenuInteraction.getValues()
, up to 100 characters, as defined byVALUE_MAX_LENGTH
- Returns:
- The new select option instance
- Throws:
IllegalArgumentException
- If the label is null, empty, or longer than 100 characters
-
withDescription
Returns a copy of this select option with the changed description of this option.
Default:null
- Parameters:
description
- The new description or null to have no description, up to 100 characters, as defined byDESCRIPTION_MAX_LENGTH
- Returns:
- The new select option instance
- Throws:
IllegalArgumentException
- If the provided description is longer than 100 characters
-
withDefault
Returns a copy of this select option with the changed default.
Default:false
- Parameters:
isDefault
- Whether this option is selected by default- Returns:
- The new select option instance
-
withEmoji
Returns a copy of this select option with the changed emoji.
Default:null
- Parameters:
emoji
- TheEmoji
shown next to this option, or null- Returns:
- The new select option instance
-
getLabel
The current option label which would be shown to the user in the client.- Returns:
- The label
-
getValue
The current option value which is used to identify the selected options inSelectMenuInteraction.getValues()
.- Returns:
- The option value
-
getDescription
The current description for this option.- Returns:
- The description
-
isDefault
public boolean isDefault()Whether this option is selected by default- Returns:
- True, if this option is selected by default
-
getEmoji
The emoji attached to this option which is shown next to the option in the select menu- Returns:
- The attached emoji
-
toData
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-
fromData
Inverse function fortoData()
which parses the serialized option data- Parameters:
data
- The serialized option data- Returns:
- The parsed SelectOption instance
- Throws:
ParsingException
- If the data representation is invalidIllegalArgumentException
- If some part of the data has an invalid length or null is provided
-