Interface SelectionMenu
-
- All Superinterfaces:
Component
,SerializableData
public interface SelectionMenu extends Component
Represents a selection menu in a message.
This is an interactive component and usually located within anActionRow
. One selection menu fills up an entire action row by itself. You cannot have an action row with other components if a selection 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 onSlashCommand(SlashCommandEvent event) { if (!event.getName().equals("class")) return; SelectionMenu menu = SelectionMenu.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(); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SelectionMenu.Builder
A preconfigured builder for the creation of selection menus.-
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.interactions.components.Component
Component.Type
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default SelectionMenu
asDisabled()
Creates a copy of this menu withisDisabled()
set to true.default SelectionMenu
asEnabled()
Creates a copy of this menu withisDisabled()
set to false.static SelectionMenu.Builder
create(java.lang.String customId)
Creates a newSelectionMenu.Builder
for a selection menu with the provided custom id.default SelectionMenu.Builder
createCopy()
Creates a new preconfiguredSelectionMenu.Builder
with the same settings used for this selection menu.static SelectionMenu.Builder
fromData(DataObject data)
Inverse function forSerializableData.toData()
which parses the serialized selection 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.java.util.List<SelectOption>
getOptions()
Up to 25 available options to choose from.java.lang.String
getPlaceholder()
Placeholder which is displayed when no selections have been made yet.boolean
isDisabled()
Whether this menu is disabled.default SelectionMenu
withDisabled(boolean disabled)
Creates a copy of this menu withisDisabled()
set to the desired value.-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.Component
getId, getMaxPerRow, getType
-
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
-
-
-
Method Detail
-
getPlaceholder
@Nullable java.lang.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 java.util.List<SelectOption> getOptions()
Up to 25 available options to choose from.- Returns:
- The
SelectOptions
this menu provides
-
isDisabled
boolean isDisabled()
Whether this menu is disabled.
You can quickly get a disabled menu from an existing menu withasDisabled()
.- Returns:
- True, if this menu is disabled
- See Also:
SelectionMenu.Builder.setDisabled(boolean)
-
asDisabled
@Nonnull @CheckReturnValue default SelectionMenu asDisabled()
Creates a copy of this menu withisDisabled()
set to true.- Returns:
- A new disabled SelectionMenu instance
- See Also:
withDisabled(boolean)
-
asEnabled
@Nonnull @CheckReturnValue default SelectionMenu asEnabled()
Creates a copy of this menu withisDisabled()
set to false.- Returns:
- A new enabled SelectionMenu instance
- See Also:
withDisabled(boolean)
-
withDisabled
@Nonnull @CheckReturnValue default SelectionMenu withDisabled(boolean disabled)
Creates a copy of this menu withisDisabled()
set to the desired value.- Parameters:
disabled
- Whether the menu should be disabled- Returns:
- A new SelectionMenu instance with
isDisabled()
set to the desired value - See Also:
withDisabled(boolean)
-
createCopy
@Nonnull @CheckReturnValue default SelectionMenu.Builder createCopy()
Creates a new preconfiguredSelectionMenu.Builder
with the same settings used for this selection menu.
This can be useful to create an updated version of this menu without needing to rebuild it from scratch.- Returns:
- The
SelectionMenu.Builder
used to create the selection menu
-
create
@Nonnull @CheckReturnValue static SelectionMenu.Builder create(@Nonnull java.lang.String customId)
Creates a newSelectionMenu.Builder
for a selection menu with the provided custom id.- Parameters:
customId
- The id used to identify this menu withComponent.getId()
for component interactions- Returns:
- The
SelectionMenu.Builder
used to create the selection menu - Throws:
java.lang.IllegalArgumentException
- If the provided id is null, empty, or longer than 100 characters
-
fromData
@Nonnull @CheckReturnValue static SelectionMenu.Builder fromData(@Nonnull DataObject data)
Inverse function forSerializableData.toData()
which parses the serialized selection menu data.
Returns aSelectionMenu.Builder
which allows for further configuration.- Parameters:
data
- The serialized selection menu data- Returns:
- The parsed SelectionMenu Builder instance
- Throws:
ParsingException
- If the data representation is invalidjava.lang.IllegalArgumentException
- If some part of the data has an invalid length or null is provided
-
-