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 an ActionRow. 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();
     }
     
    • 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
      • withDisabled

        @Nonnull
        @CheckReturnValue
        default SelectionMenu withDisabled​(boolean disabled)
        Creates a copy of this menu with isDisabled() 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 preconfigured SelectionMenu.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 new SelectionMenu.Builder for a selection menu with the provided custom id.
        Parameters:
        customId - The id used to identify this menu with Component.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 for SerializableData.toData() which parses the serialized selection menu data.
        Returns a SelectionMenu.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 invalid
        java.lang.IllegalArgumentException - If some part of the data has an invalid length or null is provided