Interface SelectMenu
-
- All Superinterfaces:
ActionComponent
,Component
,ItemComponent
,SerializableData
public interface SelectMenu extends ActionComponent
Represents a select menu in a message.
This is an interactive component and usually located within anActionRow
. One select menu fills up an entire action row by itself. You cannot have an action row with other components if a select menu is present in the same row.The selections a user makes are only visible within their current client session. Other users cannot see the choices selected, and they will disappear when the client restarts or the message is reloaded.
Examples
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { if (!event.getName().equals("class")) return; SelectMenu menu = SelectMenu.create("menu:class") .setPlaceholder("Choose your class") // shows the placeholder indicating what this menu is for .setRequireRange(1, 1) // only one can be selected .addOption("Arcane Mage", "mage-arcane") .addOption("Fire Mage", "mage-fire") .addOption("Frost Mage", "mage-frost") .build(); event.reply("Please pick your class below") .setEphemeral(true) .addActionRow(menu) .queue(); }
- See Also:
SelectMenuInteraction
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SelectMenu.Builder
A preconfigured builder for the creation of select menus.-
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.interactions.components.Component
Component.Type
-
-
Field Summary
Fields Modifier and Type Field Description static int
ID_MAX_LENGTH
The maximum length a select menu id can havestatic int
OPTIONS_MAX_AMOUNT
The maximum amount of options a select menu can havestatic int
PLACEHOLDER_MAX_LENGTH
The maximum length a select menu placeholder can have
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default SelectMenu
asDisabled()
Returns a copy of this component withActionComponent.isDisabled()
set to true.default SelectMenu
asEnabled()
Returns a copy of this component withActionComponent.isDisabled()
set to false.static SelectMenu.Builder
create(String customId)
Creates a newSelectMenu.Builder
for a select menu with the provided custom id.default SelectMenu.Builder
createCopy()
Creates a new preconfiguredSelectMenu.Builder
with the same settings used for this select menu.static SelectMenu.Builder
fromData(DataObject data)
Inverse function forSerializableData.toData()
which parses the serialized select menu data.int
getMaxValues()
The maximum amount of values a user can select at once.int
getMinValues()
The minimum amount of values a user has to select.List<SelectOption>
getOptions()
An unmodifiable list of up to 25 available options to choose from.String
getPlaceholder()
Placeholder which is displayed when no selections have been made yet.default SelectMenu
withDisabled(boolean disabled)
Returns a copy of this component withActionComponent.isDisabled()
set to the provided value.-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.ActionComponent
getId, isDisabled
-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.ItemComponent
getMaxPerRow
-
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
-
-
-
Field Detail
-
ID_MAX_LENGTH
static final int ID_MAX_LENGTH
The maximum length a select menu id can have- See Also:
- Constant Field Values
-
PLACEHOLDER_MAX_LENGTH
static final int PLACEHOLDER_MAX_LENGTH
The maximum length a select menu placeholder can have- See Also:
- Constant Field Values
-
OPTIONS_MAX_AMOUNT
static final int OPTIONS_MAX_AMOUNT
The maximum amount of options a select menu can have- See Also:
- Constant Field Values
-
-
Method Detail
-
getPlaceholder
@Nullable String getPlaceholder()
Placeholder which is displayed when no selections have been made yet.- Returns:
- The placeholder or null
-
getMinValues
int getMinValues()
The minimum amount of values a user has to select.- Returns:
- The min values
-
getMaxValues
int getMaxValues()
The maximum amount of values a user can select at once.- Returns:
- The max values
-
getOptions
@Nonnull List<SelectOption> getOptions()
An unmodifiable list of up to 25 available options to choose from.- Returns:
- The
SelectOptions
this menu provides - See Also:
SelectMenu.Builder.getOptions()
-
asDisabled
@Nonnull @CheckReturnValue default SelectMenu asDisabled()
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to true.- Specified by:
asDisabled
in interfaceActionComponent
- Returns:
- New disabled component instance
-
asEnabled
@Nonnull @CheckReturnValue default SelectMenu asEnabled()
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to false.- Specified by:
asEnabled
in interfaceActionComponent
- Returns:
- New enabled component instance
-
withDisabled
@Nonnull @CheckReturnValue default SelectMenu withDisabled(boolean disabled)
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to the provided value.- Specified by:
withDisabled
in interfaceActionComponent
- Parameters:
disabled
- True, if this component should be disabled- Returns:
- New enabled/disabled component instance
-
createCopy
@Nonnull @CheckReturnValue default SelectMenu.Builder createCopy()
Creates a new preconfiguredSelectMenu.Builder
with the same settings used for this select menu.
This can be useful to create an updated version of this menu without needing to rebuild it from scratch.- Returns:
- The
SelectMenu.Builder
used to create the select menu
-
create
@Nonnull @CheckReturnValue static SelectMenu.Builder create(@Nonnull String customId)
Creates a newSelectMenu.Builder
for a select menu with the provided custom id.- Parameters:
customId
- The id used to identify this menu withActionComponent.getId()
for component interactions- Returns:
- The
SelectMenu.Builder
used to create the select menu - Throws:
IllegalArgumentException
- If the provided id is null, empty, or longer than 100 characters
-
fromData
@Nonnull @CheckReturnValue static SelectMenu.Builder fromData(@Nonnull DataObject data)
Inverse function forSerializableData.toData()
which parses the serialized select menu data.
Returns aSelectMenu.Builder
which allows for further configuration.- Parameters:
data
- The serialized select menu data- Returns:
- The parsed SelectMenu Builder instance
- Throws:
ParsingException
- If the data representation is invalidIllegalArgumentException
- If some part of the data has an invalid length or null is provided
-
-