Class TextInput.Builder
java.lang.Object
net.dv8tion.jda.api.interactions.components.text.TextInput.Builder
- Enclosing interface:
TextInput
Builder for
TextInputs
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a new TextInput from this BuildergetId()
The custom idgetLabel()
The label shown above this text input boxint
The maximum length.int
The minimum length.The placeholder of this TextInput
This is the short hint that describes the expected value of the TextInput field.getStyle()
TheTextInputStyle
getValue()
The String value of this TextInputboolean
Whether this TextInput is required.Sets the id for this TextInput
This is used to uniquely identify it.Sets the label for this TextInputsetMaxLength
(int maxLength) Sets the maximum length of this input field.setMinLength
(int minLength) Sets the minimum length of this input field.setPlaceholder
(String placeholder) Sets a placeholder for this TextInput field.setRequired
(boolean required) Sets whether the user is required to write in this TextInput.setRequiredRange
(int min, int max) Sets the minimum and maximum required length on this TextInput componentsetStyle
(TextInputStyle style) Sets the style for this TextInput
Possible values are:TextInputStyle.SHORT
TextInputStyle.PARAGRAPH
Sets a pre-populated text for this TextInput field.
-
Method Details
-
setId
Sets the id for this TextInput
This is used to uniquely identify it.- Parameters:
id
- The id to set- Returns:
- The same Builder for chaining convenience.
- Throws:
IllegalArgumentException
-- If id is null or blank
- If id is longer than 100 characters
-
setLabel
Sets the label for this TextInput- Parameters:
label
- The label to set- Returns:
- The same Builder for chaining convenience.
- Throws:
IllegalArgumentException
-- If label is null or blank
- If label is longer than 45 characters
-
setStyle
Sets the style for this TextInput
Possible values are:- Parameters:
style
- The style to set- Returns:
- The same Builder for chaining convenience.
- Throws:
IllegalArgumentException
- If style is null orUNKNOWN
-
setRequired
Sets whether the user is required to write in this TextInput. Default is true.- Parameters:
required
- If this TextInput should be required- Returns:
- The same builder instance for chaining
-
setMinLength
Sets the minimum length of this input field. Default is -1 (No minimum length).This has to be between 0 and 4000, or -1 for no minimum length
- Parameters:
minLength
- The minimum amount of characters that need to be written, or -1- Returns:
- The same builder instance for chaining
- Throws:
IllegalArgumentException
- If minLength is not -1 and is negative or greater than 4000
-
setMaxLength
Sets the maximum length of this input field. Default is -1 (No maximum length).This has to be between 1 and 4000, or -1 for no maximum length
- Parameters:
maxLength
- The maximum amount of characters that need to be written, or -1- Returns:
- The same builder instance for chaining
- Throws:
IllegalArgumentException
- If maxLength is not -1 and is smaller than 1 or greater than 4000
-
setRequiredRange
Sets the minimum and maximum required length on this TextInput component- Parameters:
min
- Minimum length of the text input, or -1 for nonemax
- Maximum length of the text input, or -1 for none- Returns:
- The same builder instance for chaining
- Throws:
IllegalArgumentException
-- If min is not -1 and is negative or greater than
TextInput.MAX_VALUE_LENGTH
- If max is not -1 and is smaller than 1, smaller than min or greater than
TextInput.MAX_VALUE_LENGTH
- If min is not -1 and is negative or greater than
-
setValue
Sets a pre-populated text for this TextInput field.
If this is not null, sending a Modal with this component will pre-populate the TextInput field with the specified String.- Parameters:
value
- Pre-Populated text- Returns:
- The same builder instance for chaining
-
setPlaceholder
Sets a placeholder for this TextInput field.
This is a short hint that describes the expected value of the input field.- Parameters:
placeholder
- The placeholder- Returns:
- The same builder instance for chaining
- Throws:
IllegalArgumentException
- If the provided placeholder is longer thanTextInput.MAX_PLACEHOLDER_LENGTH
characters
-
getMinLength
public int getMinLength()The minimum length. This is -1 if none has been set.- Returns:
- Minimum length or -1
-
getMaxLength
public int getMaxLength()The maximum length. This is -1 if none has been set.- Returns:
- Maximum length or -1
-
getId
The custom id- Returns:
- Custom id
-
getLabel
The label shown above this text input box- Returns:
- Label for the input
-
getStyle
TheTextInputStyle
- Returns:
- The TextInputStyle
-
getPlaceholder
The placeholder of this TextInput
This is the short hint that describes the expected value of the TextInput field.- Returns:
- Placeholder
-
getValue
The String value of this TextInput- Returns:
- Value
-
isRequired
public boolean isRequired()Whether this TextInput is required.
If this is True, the user must populate this TextInput field before they can submit the Modal.- Returns:
- True if this TextInput is required
- See Also:
-
build
Builds a new TextInput from this Builder- Returns:
- the TextInput instance
- Throws:
IllegalStateException
- If maxLength is smaller than minLength
-