Class SelectMenu.Builder

java.lang.Object
net.dv8tion.jda.api.interactions.components.selections.SelectMenu.Builder
Enclosing interface:
SelectMenu

public static class SelectMenu.Builder extends Object
A preconfigured builder for the creation of select menus.
  • Method Details

    • setId

      @Nonnull public SelectMenu.Builder setId(@Nonnull String customId)
      Change the custom id used to identify the select menu.
      Parameters:
      customId - The new custom id to use
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the provided id is null, empty, or longer than 100 characters
    • setPlaceholder

      @Nonnull public SelectMenu.Builder setPlaceholder(@Nullable String placeholder)
      Configure the placeholder which is displayed when no selections have been made yet.
      Parameters:
      placeholder - The placeholder or null
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the provided placeholder is empty or longer than 100 characters
    • setMinValues

      @Nonnull public SelectMenu.Builder setMinValues(int minValues)
      The minimum amount of values a user has to select.
      Default: 1

      The minimum must not exceed the amount of available options.

      Parameters:
      minValues - The min values
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the provided amount is negative or greater than 25
    • setMaxValues

      @Nonnull public SelectMenu.Builder setMaxValues(int maxValues)
      The maximum amount of values a user can select.
      Default: 1

      The maximum must not exceed the amount of available options.

      Parameters:
      maxValues - The max values
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the provided amount is less than 1 or greater than 25
    • setRequiredRange

      @Nonnull public SelectMenu.Builder setRequiredRange(int min, int max)
      The minimum and maximum amount of values a user can select.
      Default: 1 for both

      The minimum or maximum must not exceed the amount of available options.

      Parameters:
      min - The min values
      max - The max values
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the provided amount is not a valid range (0 <= min <= max)
    • setDisabled

      @Nonnull public SelectMenu.Builder setDisabled(boolean disabled)
      Configure whether this select menu should be disabled.
      Default: false
      Parameters:
      disabled - Whether this menu is disabled
      Returns:
      The same builder instance for chaining
    • addOptions

      @Nonnull public SelectMenu.Builder addOptions(@Nonnull SelectOption... options)
      Adds up to 25 possible options to this select menu.
      Parameters:
      options - The SelectOptions to add
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25 or null is provided
      See Also:
    • addOptions

      @Nonnull public SelectMenu.Builder addOptions(@Nonnull Collection<? extends SelectOption> options)
      Adds up to 25 possible options to this select menu.
      Parameters:
      options - The SelectOptions to add
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25 or null is provided
      See Also:
    • addOption

      @Nonnull public SelectMenu.Builder addOption(@Nonnull String label, @Nonnull String value)
      Adds up to 25 possible options to this select menu.
      Parameters:
      label - The label for the option, up to 100 characters
      value - The value for the option used to indicate which option was selected with SelectMenuInteraction.getValues(), up to 100 characters
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25, invalid null is provided, or any of the individual parameter requirements are violated.
    • addOption

      @Nonnull public SelectMenu.Builder addOption(@Nonnull String label, @Nonnull String value, @Nonnull Emoji emoji)
      Adds up to 25 possible options to this select menu.
      Parameters:
      label - The label for the option, up to 100 characters
      value - The value for the option used to indicate which option was selected with SelectMenuInteraction.getValues(), up to 100 characters
      emoji - The Emoji shown next to this option, or null
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25, invalid null is provided, or any of the individual parameter requirements are violated.
    • addOption

      @Nonnull public SelectMenu.Builder addOption(@Nonnull String label, @Nonnull String value, @Nonnull String description)
      Adds up to 25 possible options to this select menu.
      Parameters:
      label - The label for the option, up to 100 characters
      value - The value for the option used to indicate which option was selected with SelectMenuInteraction.getValues(), up to 100 characters
      description - The description explaining the meaning of this option in more detail, up to 50 characters
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25, invalid null is provided, or any of the individual parameter requirements are violated.
    • addOption

      @Nonnull public SelectMenu.Builder addOption(@Nonnull String label, @Nonnull String value, @Nullable String description, @Nullable Emoji emoji)
      Adds up to 25 possible options to this select menu.
      Parameters:
      label - The label for the option, up to 100 characters
      value - The value for the option used to indicate which option was selected with SelectMenuInteraction.getValues(), up to 100 characters
      description - The description explaining the meaning of this option in more detail, up to 50 characters
      emoji - The Emoji shown next to this option, or null
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the total amount of options is greater than 25, invalid null is provided, or any of the individual parameter requirements are violated.
    • getOptions

      @Nonnull public List<SelectOption> getOptions()
      Modifiable list of options currently configured in this builder.
      Returns:
      The list of SelectOptions
    • setDefaultValues

      @Nonnull public SelectMenu.Builder setDefaultValues(@Nonnull Collection<String> values)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      values - The option values
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If null is provided
    • setDefaultOptions

      @Nonnull public SelectMenu.Builder setDefaultOptions(@Nonnull Collection<? extends SelectOption> values)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      values - The SelectOptions
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If null is provided
    • getId

      @Nonnull public String getId()
      The custom id used to identify the select menu.
      Returns:
      The custom id
    • getPlaceholder

      @Nullable public String getPlaceholder()
      Placeholder which is displayed when no selections have been made yet.
      Returns:
      The placeholder or null
    • getMinValues

      public int getMinValues()
      The minimum amount of values a user has to select.
      Returns:
      The min values
    • getMaxValues

      public int getMaxValues()
      The maximum amount of values a user can select at once.
      Returns:
      The max values
    • isDisabled

      public boolean isDisabled()
      Whether the menu is disabled
      Returns:
      True if this menu is disabled
    • build

      @Nonnull public SelectMenu build()
      Creates a new SelectMenu instance if all requirements are satisfied.
      A select menu may not have more than 25 options at once.

      The values for setMinValues(int) and setMaxValues(int) are bounded by the length of getOptions(). This means they will automatically be adjusted to not be greater than getOptions().size().

      Returns:
      The new SelectMenu instance
      Throws:
      IllegalArgumentException - Throws if getMinValues() is greater than getMaxValues() or more than 25 options are provided