Interface StringSelectMenu
- All Superinterfaces:
ActionComponent
,ActionRowChildComponent
,Component
,IDisableable
,SelectMenu
- All Known Implementing Classes:
StringSelectMenuImpl
Represents a select menu in a message.
This is an interactive component and usually located within an
This is an interactive component and usually located within an
ActionRow
.
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;
StringSelectMenu menu = StringSelectMenu.create("menu:class")
.setPlaceholder("Choose your class") // shows the placeholder indicating what this menu is for
.setRequiredRange(1, 1) // exactly one must be selected
.addOption("Arcane Mage", "mage-arcane")
.addOption("Fire Mage", "mage-fire")
.addOption("Frost Mage", "mage-frost")
.setDefaultValues("mage-fire") // default to fire mage
.build();
event.reply("Please pick your class below")
.setEphemeral(true)
.addComponents(ActionRow.of(menu))
.queue();
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
A preconfigured builder for the creation of string select menus.Nested classes/interfaces inherited from interface net.dv8tion.jda.api.components.Component
Component.Type
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.components.selections.SelectMenu
ID_MAX_LENGTH, OPTIONS_MAX_AMOUNT, PLACEHOLDER_MAX_LENGTH
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringSelectMenu
Returns a copy of this component withActionComponent.isDisabled()
set to true.default StringSelectMenu
Returns a copy of this component withActionComponent.isDisabled()
set to false.static StringSelectMenu.Builder
Creates a newStringSelectMenu.Builder
for a select menu with the provided custom id.default StringSelectMenu.Builder
Creates a new preconfiguredStringSelectMenu.Builder
with the same settings used for this select menu.An unmodifiable list of up to 25 available options to choose from.default StringSelectMenu
withDisabled
(boolean disabled) Returns a copy of this component withActionComponent.isDisabled()
set to the provided value.withUniqueId
(int uniqueId) Creates a new component with the provided numeric ID.Methods inherited from interface net.dv8tion.jda.api.components.ActionComponent
getId, isDisabled
Methods inherited from interface net.dv8tion.jda.api.components.Component
getType, getUniqueId, isMessageCompatible, isModalCompatible
Methods inherited from interface net.dv8tion.jda.api.components.attribute.IDisableable
isEnabled
Methods inherited from interface net.dv8tion.jda.api.components.selections.SelectMenu
getCustomId, getMaxValues, getMinValues, getPlaceholder
-
Method Details
-
asDisabled
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to true.- Specified by:
asDisabled
in interfaceActionComponent
- Specified by:
asDisabled
in interfaceIDisableable
- Specified by:
asDisabled
in interfaceSelectMenu
- Returns:
- New disabled component instance
- See Also:
-
asEnabled
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to false.- Specified by:
asEnabled
in interfaceActionComponent
- Specified by:
asEnabled
in interfaceIDisableable
- Specified by:
asEnabled
in interfaceSelectMenu
- Returns:
- New enabled component instance
- See Also:
-
withDisabled
Description copied from interface:ActionComponent
Returns a copy of this component withActionComponent.isDisabled()
set to the provided value.- Specified by:
withDisabled
in interfaceActionComponent
- Specified by:
withDisabled
in interfaceIDisableable
- Specified by:
withDisabled
in interfaceSelectMenu
- Parameters:
disabled
- True, if this component should be disabled- Returns:
- New enabled/disabled component instance
- See Also:
-
withUniqueId
Description copied from interface:Component
Creates a new component with the provided numeric ID.
If no ID is set, Discord will generate IDs incrementally starting from 1 and will not use existing IDs from the same message/modal.- Specified by:
withUniqueId
in interfaceActionComponent
- Specified by:
withUniqueId
in interfaceActionRowChildComponent
- Specified by:
withUniqueId
in interfaceComponent
- Specified by:
withUniqueId
in interfaceIDisableable
- Specified by:
withUniqueId
in interfaceSelectMenu
- Parameters:
uniqueId
- The new ID; must be higher or equal to 1- Returns:
- The new component
-
getOptions
An unmodifiable list of up to 25 available options to choose from.- Returns:
- The
SelectOptions
this menu provides - See Also:
-
createCopy
Creates a new preconfiguredStringSelectMenu.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.- Specified by:
createCopy
in interfaceSelectMenu
- Returns:
- The
StringSelectMenu.Builder
used to create the select menu
-
create
Creates a newStringSelectMenu.Builder
for a select menu with the provided custom id.- Parameters:
customId
- The id used to identify this menu withActionComponent.getCustomId()
for component interactions- Returns:
- The
StringSelectMenu.Builder
used to create the select menu - Throws:
IllegalArgumentException
- If the provided id is null, empty, or longer than 100 characters
-