Class SelectMenu.Builder<T extends SelectMenu,B extends SelectMenu.Builder<T,B>>

java.lang.Object
net.dv8tion.jda.api.components.selections.SelectMenu.Builder<T,B>
Type Parameters:
T - The output type
B - The builder type (used for fluent interface)
Direct Known Subclasses:
EntitySelectMenu.Builder, StringSelectMenu.Builder
Enclosing interface:
SelectMenu

public abstract static class SelectMenu.Builder<T extends SelectMenu,B extends SelectMenu.Builder<T,B>> extends Object
A preconfigured builder for the creation of select menus.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract T
    Creates a new SelectMenu instance if all requirements are satisfied.
    The custom id used to identify the select menu.
    int
    The maximum amount of values a user can select at once.
    int
    The minimum amount of values a user has to select.
    Placeholder which is displayed when no selections have been made yet.
    int
    The numeric id used to identify the select menu.
    boolean
    Whether the menu is disabled
    Whether the user must populate this select menu in Modals, or null if not set.
    setCustomId(String customId)
    Change the custom id used to identify the select menu.
    setDisabled(boolean disabled)
    Configure whether this select menu should be disabled.
    setMaxValues(int maxValues)
    The maximum amount of values a user can select.
    setMinValues(int minValues)
    The minimum amount of values a user has to select.
    setPlaceholder(String placeholder)
    Configure the placeholder which is displayed when no selections have been made yet.
    setRequired(Boolean required)
    Configure whether the user must populate this select menu if inside a Modal.
    setRequiredRange(int min, int max)
    The minimum and maximum amount of values a user can select.
    setUniqueId(int uniqueId)
    Changes the numeric ID used to identify the select menu.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setCustomId

      @Nonnull public B setCustomId(@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
    • setUniqueId

      @Nonnull public B setUniqueId(int uniqueId)
      Changes the numeric ID used to identify the select menu.
      Parameters:
      uniqueId - The new ID, must not be negative
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException - If the ID is negative
    • setPlaceholder

      @Nonnull public B 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 B 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 B 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 B 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 B 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
    • setRequired

      @Nonnull public B setRequired(@Nullable Boolean required)
      Configure whether the user must populate this select menu if inside a Modal.
      This defaults to true in Modals when unset.

      This attribute is completely separate from the value range, for example, you can have an optional select menu with the range set to [2 ; 5], meaning you accept either 0 options, or, at least 2 but at most 5.

      This only has an effect in Modals!

      Parameters:
      required - Whether this menu is required
      Returns:
      The same builder instance for chaining
    • getCustomId

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

      public int getUniqueId()
      The numeric id used to identify the select menu.
      Returns:
      The numeric 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
    • isRequired

      @Nullable public Boolean isRequired()
      Whether the user must populate this select menu in Modals, or null if not set.

      This attribute is completely separate from the value range, for example, you can have an optional select menu with the range set to [2 ; 5], meaning you accept either 0 options, or, at least 2 but at most 5.

      Returns:
      Whether this menu must be populated, or null
    • build

      @Nonnull public abstract T build()
      Creates a new SelectMenu instance if all requirements are satisfied.
      Returns:
      The new SelectMenu instance
      Throws:
      IllegalArgumentException - Throws if getMinValues() is greater than getMaxValues()