Interface StringSelectMenuHandler
public interface StringSelectMenuHandler
An interface that contains the method that should be executed when a user interacts with a
StringSelectMenu
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleStringSelectMenu
(net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent event, List<String> values) Method that must be overridden for all classes that handleStringSelectInteraction
.
-
Method Details
-
handleStringSelectMenu
void handleStringSelectMenu(@Nonnull net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent event, @Nonnull List<String> values) Method that must be overridden for all classes that handleStringSelectInteraction
. All select menus that match the identifier will execute this class's implementation of the handleStringSelectMenu method. This is best used with theComponentIdBuilder
.
In order for this to work, you manually have to configure the corresponding string-select menu mappings like that:public class TestCommand extends SlashCommand implements StringSelectMenuHandler { public TestCommand() { setCommandData(Commands.slash("test", "test description")); } @Override public void execute(SlashCommandInteractionEvent event) { List<Role> roles = [...] SelectMenu.Builder menu = SelectMenu.create("test-select-menu"); for (Role role : roles) { menu.addOption(role.getName(), role.getId()); } event.reply("Choose your rank!").addActionRow(menu.build()).queue(); } @Override public void handleStringSelectMenu(StringSelectInteractionEvent event, List<String> values) { for (String roleId : values) { event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(roleId)).queue(); } event.reply("Successfully added " + String.join(", ", event.getValues())).queue(); } }
dih4JDA.addStringSelectMenuMappings(IdMapping.of(new TestCommand(), "test-string-select-menu"));
- Parameters:
event
- the providedStringSelectInteractionEvent
.values
- the provided selections.- Since:
- v1.4
- See Also:
-