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 Type
    Method
    Description
    void
    handleStringSelectMenu(net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent event, List<String> values)
    Method that must be overridden for all classes that handle StringSelectInteraction.
  • 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 handle StringSelectInteraction. All select menus that match the identifier will execute this class's implementation of the handleStringSelectMenu method. This is best used with the ComponentIdBuilder.
      
       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();
          }
       }
       
      In order for this to work, you manually have to configure the corresponding string-select menu mappings like that:
      
       dih4JDA.addStringSelectMenuMappings(IdMapping.of(new TestCommand(), "test-string-select-menu"));
       
      Parameters:
      event - the provided StringSelectInteractionEvent.
      values - the provided selections.
      Since:
      v1.4
      See Also: