Class CheckboxGroup.Builder

java.lang.Object
net.dv8tion.jda.api.components.checkboxgroup.CheckboxGroup.Builder
Enclosing interface:
CheckboxGroup

public static class CheckboxGroup.Builder extends Object
Builder of CheckboxGroup
See Also:
  • Method Details

    • getUniqueId

      public int getUniqueId()
      The unique ID of this checkbox group, or -1 if it isn't set.
      Returns:
      The unique ID, or -1
    • getCustomId

      @Nonnull public String getCustomId()
      The custom ID of this checkbox group.
      Returns:
      The custom ID
    • getMinValues

      public int getMinValues()
      The minimum number of values the user has to select.
      Returns:
      Minimum number of values the user has to select
    • getMaxValues

      public int getMaxValues()
      The maximum number of values the user can select.
      Returns:
      Maximum number of values the user can select
    • isRequired

      public boolean isRequired()
      Whether this checkbox group should, if at least one option is selected, enforce the value range before sending.
      Returns:
      true if the value range should be enforced
    • setUniqueId

      @Nonnull public CheckboxGroup.Builder setUniqueId(int uniqueId)
      Sets the unique ID of this checkbox group.
      This is used to identify components in the tree.
      Parameters:
      uniqueId - The new unique ID, must be positive
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the ID is negative or zero
    • setCustomId

      @Nonnull public CheckboxGroup.Builder setCustomId(@Nonnull String customId)
      Sets the custom ID of this checkbox group.
      This is typically used to carry data between the modal creator and the modal handler.
      Parameters:
      customId - The new custom ID
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the ID is null, blank, or longer than 100 characters
    • addOptions

      @Nonnull public CheckboxGroup.Builder addOptions(@Nonnull CheckboxGroupOption... options)
      Adds the provided options to this checkbox group.
      Parameters:
      options - The options to add
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the array or an element is null
    • addOptions

      @Nonnull public CheckboxGroup.Builder addOptions(@Nonnull Collection<? extends CheckboxGroupOption> options)
      Adds the provided options to this checkbox group.
      Parameters:
      options - The options to add
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the collection or an element is null
    • addOption

      @Nonnull public CheckboxGroup.Builder addOption(@Nonnull String label, @Nonnull String value)
      Adds an option to this checkbox group.
      Parameters:
      label - The label to be displayed next to the checkbox, up to 100 characters
      value - The value associated to the option, this is what your bot will receive, up to 100 characters
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the label or value is null or blank, or one of them is longer than allowed
    • addOption

      @Nonnull public CheckboxGroup.Builder addOption(@Nonnull String label, @Nonnull String value, @Nullable String description)
      Adds an option to this checkbox group.
      Parameters:
      label - The label to be displayed next to the checkbox, up to 100 characters
      value - The value associated to the option, this is what your bot will receive, up to 100 characters
      description - The description of this checkbox, up to 100 characters
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the label or value is null or blank, the description is blank, or one of them is longer than allowed
    • addOption

      @Nonnull public CheckboxGroup.Builder addOption(@Nonnull String label, @Nonnull String value, @Nullable String description, boolean isDefault)
      Adds an option to this checkbox group.
      Parameters:
      label - The label to be displayed next to the checkbox, up to 100 characters
      value - The value associated to the option, this is what your bot will receive, up to 100 characters
      description - The description of this checkbox, up to 100 characters
      isDefault - Whether this option will be selected by default
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the label or value is null or blank, or the description is blank, or one of them is longer than allowed
    • getOptions

      @Nonnull public List<CheckboxGroupOption> getOptions()
      Returns a modifiable list of checkbox group options.
      Returns:
      The modifiable list of options
    • setMinValues

      @Nonnull public CheckboxGroup.Builder setMinValues(int minValues)
      Sets the minimum number of values the user has to select.

      If you set this to zero, you must set this checkbox group as optional.

      Parameters:
      minValues - Minimum number of values to select
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the value is negative or greater than 10
    • setMaxValues

      @Nonnull public CheckboxGroup.Builder setMaxValues(int maxValues)
      Sets the maximum number of values the user can select.
      Parameters:
      maxValues - Maximum number of selectable values
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If the value is zero, negative, or, greater than 10
    • setRequiredRange

      @Nonnull public CheckboxGroup.Builder setRequiredRange(int minValues, int maxValues)
      Sets the minimum and maximum number of values the user has to select.

      If you set the minimum to zero, you must set this checkbox group as optional.

      Parameters:
      minValues - Minimum number of values to select
      maxValues - Maximum number of selectable values
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException -
      • If the min value is negative or greater than 10
      • If the max value is zero, negative, or, greater than 10
    • setRequired

      @Nonnull public CheckboxGroup.Builder setRequired(boolean required)
      Sets whether this checkbox group must have at least the minimum amount of options be selected.

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

      Checkbox groups are required by default.

      Parameters:
      required - true if the value range must be enforced when at least one value is selected
      Returns:
      This instance for chaining convenience
    • setSelectedValues

      @Nonnull public CheckboxGroup.Builder setSelectedValues(@Nonnull Collection<String> values)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      values - The option values to select
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If null is provided
    • setSelectedValues

      @Nonnull public CheckboxGroup.Builder setSelectedValues(@Nonnull String... values)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      values - The option values to select
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If null is provided
    • setSelectedOptions

      @Nonnull public CheckboxGroup.Builder setSelectedOptions(@Nonnull CheckboxGroupOption... options)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      options - The options to select
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If null is provided
    • setSelectedOptions

      @Nonnull public CheckboxGroup.Builder setSelectedOptions(@Nonnull Collection<CheckboxGroupOption> options)
      Configures which of the currently applied options should be selected by default.
      Parameters:
      options - The options to select
      Returns:
      This instance for chaining convenience
      Throws:
      IllegalArgumentException - If null is provided
    • build

      @Nonnull public CheckboxGroup build()
      Builds a new CheckboxGroup from the current configuration.
      Returns:
      The new CheckboxGroup
      Throws:
      IllegalStateException -
      • If no options have been set
      • If there is more than 10 options
      • If the minimum value range is greater than the maximum value range
      • If the minimum value range is 0 and is also required