Class TextInput.Builder

java.lang.Object
net.dv8tion.jda.api.interactions.components.text.TextInput.Builder
Enclosing interface:
TextInput

public static class TextInput.Builder extends Object
Builder for TextInputs
  • 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

      @Nonnull public TextInput.Builder setLabel(@Nonnull String label)
      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

      @Nonnull public TextInput.Builder setStyle(TextInputStyle style)
      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 or UNKNOWN
    • setRequired

      @Nonnull public TextInput.Builder setRequired(boolean required)
      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

      @Nonnull public TextInput.Builder setMinLength(int minLength)
      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

      @Nonnull public TextInput.Builder setMaxLength(int maxLength)
      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

      @Nonnull public TextInput.Builder setRequiredRange(int min, int max)
      Sets the minimum and maximum required length on this TextInput component
      Parameters:
      min - Minimum length of the text input, or -1 for none
      max - Maximum length of the text input, or -1 for none
      Returns:
      The same builder instance for chaining
      Throws:
      IllegalArgumentException -
    • setValue

      @Nonnull public TextInput.Builder setValue(@Nullable String value)
      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

      @Nonnull public TextInput.Builder setPlaceholder(@Nullable String placeholder)
      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 than TextInput.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

      @Nonnull public String getId()
      The custom id
      Returns:
      Custom id
    • getLabel

      @Nonnull public String getLabel()
      The label shown above this text input box
      Returns:
      Label for the input
    • getStyle

      @Nonnull public TextInputStyle getStyle()
      Returns:
      The TextInputStyle
    • getPlaceholder

      @Nullable public String getPlaceholder()
      The placeholder of this TextInput
      This is the short hint that describes the expected value of the TextInput field.
      Returns:
      Placeholder
    • getValue

      @Nullable public String 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

      @Nonnull public TextInput build()
      Builds a new TextInput from this Builder
      Returns:
      the TextInput instance
      Throws:
      IllegalStateException - If maxLength is smaller than minLength