Class TextInput.Builder

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

public static class TextInput.Builder extends Object
Builder for TextInputs
  • Method Details

    • setCustomId

      @Nonnull public TextInput.Builder setCustomId(@Nonnull String customId)
      Sets the custom ID for this TextInput
      This can be used to uniquely identify it, or pass data to other handlers.
      Parameters:
      customId - The custom ID to set
      Returns:
      The same Builder for chaining convenience.
      Throws:
      IllegalArgumentException -
      • If customId is null or blank
      • If customId is longer than 100 characters
    • setUniqueId

      @Nonnull public TextInput.Builder setUniqueId(int uniqueId)
      Sets the unique ID for this TextInput
      This is used to uniquely identify it.
      Parameters:
      uniqueId - The unique id to set
      Returns:
      The same Builder for chaining convenience.
      Throws:
      IllegalArgumentException - If the id is negative
    • 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 or UNKNOWN
    • setRequired

      @Nonnull public TextInput.Builder setRequired(boolean required)
      Sets whether the user is required to write in this TextInput. Default is true.

      This attribute is completely separate from the length range, for example, you can have an optional text input with the range set to [2 ; 5], meaning you accept either no input, or, at least 2 characters but at most 5.

      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
    • getCustomId

      @Nonnull public String getCustomId()
      The custom id
      Returns:
      Custom id
    • getUniqueId

      public int getUniqueId()
      The numeric unique ID
      Returns:
      Unique ID
    • 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.

      This attribute is completely separate from the length range, for example, you can have an optional text input with the range set to [2 ; 5], meaning you accept either no input, or, at least 2 characters but at most 5.

      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