Class SelectionMenu.Builder
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.components.selections.SelectionMenu.Builder
-
- Enclosing interface:
- SelectionMenu
public static class SelectionMenu.Builder extends java.lang.Object
A preconfigured builder for the creation of selection menus.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectionMenu.Builder
addOption(java.lang.String label, java.lang.String value)
Adds up to 25 possible options to this selection menu.SelectionMenu.Builder
addOption(java.lang.String label, java.lang.String value, java.lang.String description)
Adds up to 25 possible options to this selection menu.SelectionMenu.Builder
addOption(java.lang.String label, java.lang.String value, java.lang.String description, Emoji emoji)
Adds up to 25 possible options to this selection menu.SelectionMenu.Builder
addOption(java.lang.String label, java.lang.String value, Emoji emoji)
Adds up to 25 possible options to this selection menu.SelectionMenu.Builder
addOptions(java.util.Collection<? extends SelectOption> options)
Adds up to 25 possible options to this selection menu.SelectionMenu.Builder
addOptions(SelectOption... options)
Adds up to 25 possible options to this selection menu.SelectionMenu
build()
Creates a newSelectionMenu
instance if all requirements are satisfied.java.lang.String
getId()
The custom id used to identify the selection menu.int
getMaxValues()
The maximum amount of values a user can select at once.int
getMinValues()
The minimum amount of values a user has to select.java.util.List<SelectOption>
getOptions()
Modifiable list of options currently configured in this builder.java.lang.String
getPlaceholder()
Placeholder which is displayed when no selections have been made yet.boolean
isDisabled()
Whether the menu is disabledSelectionMenu.Builder
setDefaultOptions(java.util.Collection<? extends SelectOption> values)
Configures which of the currently appliedoptions
should be selected by default.SelectionMenu.Builder
setDefaultValues(java.util.Collection<java.lang.String> values)
Configures which of the currently appliedoptions
should be selected by default.SelectionMenu.Builder
setDisabled(boolean disabled)
Configure whether this selection menu should be disabled.SelectionMenu.Builder
setId(java.lang.String customId)
Change the custom id used to identify the selection menu.SelectionMenu.Builder
setMaxValues(int maxValues)
The maximum amount of values a user can select.SelectionMenu.Builder
setMinValues(int minValues)
The minimum amount of values a user has to select.SelectionMenu.Builder
setPlaceholder(java.lang.String placeholder)
Configure the placeholder which is displayed when no selections have been made yet.SelectionMenu.Builder
setRequiredRange(int min, int max)
The minimum and maximum amount of values a user can select.
-
-
-
Method Detail
-
setId
@Nonnull public SelectionMenu.Builder setId(@Nonnull java.lang.String customId)
Change the custom id used to identify the selection menu.- Parameters:
customId
- The new custom id to use- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If the provided id is null, empty, or longer than 100 characters
-
setPlaceholder
@Nonnull public SelectionMenu.Builder setPlaceholder(@Nullable java.lang.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:
java.lang.IllegalArgumentException
- If the provided placeholder is empty or longer than 100 characters
-
setMinValues
@Nonnull public SelectionMenu.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:
java.lang.IllegalArgumentException
- If the provided amount is negative or greater than 25
-
setMaxValues
@Nonnull public SelectionMenu.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:
java.lang.IllegalArgumentException
- If the provided amount is less than 1 or greater than 25
-
setRequiredRange
@Nonnull public SelectionMenu.Builder setRequiredRange(int min, int max)
The minimum and maximum amount of values a user can select.
Default:1
for bothThe minimum or maximum must not exceed the amount of available options.
- Parameters:
min
- The min valuesmax
- The max values- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If the provided amount is not a valid range (0 <= min <= max
)
-
setDisabled
@Nonnull public SelectionMenu.Builder setDisabled(boolean disabled)
Configure whether this selection menu should be disabled.
Default:false
- Parameters:
disabled
- Whether this menu is disabled- Returns:
- The same builder instance for chaining
-
addOptions
@Nonnull public SelectionMenu.Builder addOptions(@Nonnull SelectOption... options)
Adds up to 25 possible options to this selection menu.- Parameters:
options
- TheSelectOptions
to add- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If the total amount of options is greater than 25 or null is provided- See Also:
SelectOption.of(String, String)
-
addOptions
@Nonnull public SelectionMenu.Builder addOptions(@Nonnull java.util.Collection<? extends SelectOption> options)
Adds up to 25 possible options to this selection menu.- Parameters:
options
- TheSelectOptions
to add- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If the total amount of options is greater than 25 or null is provided- See Also:
SelectOption.of(String, String)
-
addOption
@Nonnull public SelectionMenu.Builder addOption(@Nonnull java.lang.String label, @Nonnull java.lang.String value)
Adds up to 25 possible options to this selection menu.- Parameters:
label
- The label for the option, up to 25 charactersvalue
- The value for the option used to indicate which option was selected withSelectionMenuInteraction.getValues()
, up to 100 characters- Returns:
- The same builder instance for chaining
- Throws:
java.lang.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 SelectionMenu.Builder addOption(@Nonnull java.lang.String label, @Nonnull java.lang.String value, @Nonnull Emoji emoji)
Adds up to 25 possible options to this selection menu.- Parameters:
label
- The label for the option, up to 25 charactersvalue
- The value for the option used to indicate which option was selected withSelectionMenuInteraction.getValues()
, up to 100 charactersemoji
- TheEmoji
shown next to this option, or null- Returns:
- The same builder instance for chaining
- Throws:
java.lang.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 SelectionMenu.Builder addOption(@Nonnull java.lang.String label, @Nonnull java.lang.String value, @Nonnull java.lang.String description)
Adds up to 25 possible options to this selection menu.- Parameters:
label
- The label for the option, up to 25 charactersvalue
- The value for the option used to indicate which option was selected withSelectionMenuInteraction.getValues()
, up to 100 charactersdescription
- The description explaining the meaning of this option in more detail, up to 50 characters- Returns:
- The same builder instance for chaining
- Throws:
java.lang.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 SelectionMenu.Builder addOption(@Nonnull java.lang.String label, @Nonnull java.lang.String value, @Nullable java.lang.String description, @Nullable Emoji emoji)
Adds up to 25 possible options to this selection menu.- Parameters:
label
- The label for the option, up to 25 charactersvalue
- The value for the option used to indicate which option was selected withSelectionMenuInteraction.getValues()
, up to 100 charactersdescription
- The description explaining the meaning of this option in more detail, up to 50 charactersemoji
- TheEmoji
shown next to this option, or null- Returns:
- The same builder instance for chaining
- Throws:
java.lang.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 java.util.List<SelectOption> getOptions()
Modifiable list of options currently configured in this builder.- Returns:
- The list of
SelectOptions
-
setDefaultValues
@Nonnull public SelectionMenu.Builder setDefaultValues(@Nonnull java.util.Collection<java.lang.String> values)
Configures which of the currently appliedoptions
should be selected by default.- Parameters:
values
- Theoption values
- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
setDefaultOptions
@Nonnull public SelectionMenu.Builder setDefaultOptions(@Nonnull java.util.Collection<? extends SelectOption> values)
Configures which of the currently appliedoptions
should be selected by default.- Parameters:
values
- TheSelectOptions
- Returns:
- The same builder instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
getId
@Nonnull public java.lang.String getId()
The custom id used to identify the selection menu.- Returns:
- The custom id
-
getPlaceholder
@Nullable public java.lang.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 SelectionMenu build()
Creates a newSelectionMenu
instance if all requirements are satisfied.
A selection menu may not have more than 25 options at once.The values for
setMinValues(int)
andsetMaxValues(int)
are bounded by the length ofgetOptions()
. This means they will automatically be adjusted to not be greater thangetOptions().size()
.- Returns:
- The new
SelectionMenu
instance - Throws:
java.lang.IllegalArgumentException
- Throws ifgetMinValues()
is greater thangetMaxValues()
or more than 25 options are provided
-
-