Class CheckboxGroup.Builder
java.lang.Object
net.dv8tion.jda.api.components.checkboxgroup.CheckboxGroup.Builder
- Enclosing interface:
CheckboxGroup
-
Method Summary
Modifier and TypeMethodDescriptionAdds an option to this checkbox group.Adds an option to this checkbox group.Adds an option to this checkbox group.addOptions(Collection<? extends CheckboxGroupOption> options) Adds the provided options to this checkbox group.addOptions(CheckboxGroupOption... options) Adds the provided options to this checkbox group.build()Builds a newCheckboxGroupfrom the current configuration.The custom ID of this checkbox group.intThe maximum number of values the user can select.intThe minimum number of values the user has to select.Returns a modifiable list of checkbox group options.intThe unique ID of this checkbox group, or-1if it isn't set.booleanWhether this checkbox group should, if at least one option is selected, enforce the value range before sending.setCustomId(String customId) Sets the custom ID of this checkbox group.setMaxValues(int maxValues) Sets the maximum number of values the user can select.setMinValues(int minValues) Sets the minimum number of values the user has to select.setRequired(boolean required) Sets whether this checkbox group must have at least the minimum amount of options be selected.setRequiredRange(int minValues, int maxValues) Sets the minimum and maximum number of values the user has to select.setSelectedOptions(Collection<CheckboxGroupOption> options) Configures which of the currently applied options should be selected by default.setSelectedOptions(CheckboxGroupOption... options) Configures which of the currently applied options should be selected by default.setSelectedValues(String... values) Configures which of the currently applied options should be selected by default.setSelectedValues(Collection<String> values) Configures which of the currently applied options should be selected by default.setUniqueId(int uniqueId) Sets the unique ID of this checkbox group.
-
Method Details
-
getUniqueId
public int getUniqueId()The unique ID of this checkbox group, or-1if it isn't set.- Returns:
- The unique ID, or
-1
-
getCustomId
-
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:
trueif the value range should be enforced
-
setUniqueId
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
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 isnull, blank, or longer than 100 characters
-
addOptions
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 isnull
-
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 isnull
-
addOption
Adds an option to this checkbox group.- Parameters:
label- The label to be displayed next to the checkbox, up to 100 charactersvalue- 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 isnullor 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 charactersvalue- The value associated to the option, this is what your bot will receive, up to 100 charactersdescription- The description of this checkbox, up to 100 characters- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException- If the label or value isnullor 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 charactersvalue- The value associated to the option, this is what your bot will receive, up to 100 charactersdescription- The description of this checkbox, up to 100 charactersisDefault- Whether this option will be selected by default- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException- If the label or value isnullor blank, or the description is blank, or one of them is longer than allowed
-
getOptions
Returns a modifiable list of checkbox group options.- Returns:
- The modifiable list of options
-
setMinValues
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
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
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 selectmaxValues- Maximum number of selectable values- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException-
-
setRequired
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-trueif the value range must be enforced when at least one value is selected- Returns:
- This instance for chaining convenience
-
setSelectedValues
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- Ifnullis provided
-
setSelectedValues
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- Ifnullis provided
-
setSelectedOptions
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- Ifnullis 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- Ifnullis provided
-
build
Builds a newCheckboxGroupfrom 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
-