All Superinterfaces:
SerializableData

public interface Modal extends SerializableData
Represents a Discord Modal

Replying to an interaction with a modal will open an interactive popout on the User's Discord client. This is similar to the ban modal where you can input a ban reason.

Example


 public void onSlashCommandInteraction(@Nonnull SlashCommandInteractionEvent event)
 {
     if (event.getName().equals("modmail"))
     {
         TextInput subject = TextInput.create("subject", "Subject", TextInputStyle.SHORT)
                 .setPlaceholder("Subject of this ticket")
                 .setMinLength(10)
                 .setMaxLength(100) // or setRequiredRange(10, 100)
                 .build();

         TextInput body = TextInput.create("body", "Body", TextInputStyle.PARAGRAPH)
                 .setPlaceholder("Your concerns go here")
                 .setMinLength(30)
                 .setMaxLength(1000)
                 .build();

         Modal modal = Modal.create("modmail", "Modmail")
                 .addActionRows(ActionRow.of(subject), ActionRow.of(body))
                 .build();

         event.replyModal(modal).queue();
     }
 }

Only a maximum of 5 component layouts can be included in a Modal, and only TextInputs are allowed at this time. You can check whether a component is supported via Component.Type.isModalCompatible().

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    A preconfigured builder for the creation of modals.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum amount of components a Modal can have.
    static final int
    The maximum length a modal custom id can have.
    static final int
    The maximum length a modal title can have.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(String customId, String title)
    Creates a new Modal.
    Creates a new preconfigured Modal.Builder with the same settings used for this modal.
    A List of ActionRows that this modal contains.
    The custom id of this modal
    The title of this modal

    Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData

    toData
  • Field Details

    • MAX_COMPONENTS

      static final int MAX_COMPONENTS
      The maximum amount of components a Modal can have. (5)
      See Also:
    • MAX_ID_LENGTH

      static final int MAX_ID_LENGTH
      The maximum length a modal custom id can have. (100)
      See Also:
    • MAX_TITLE_LENGTH

      static final int MAX_TITLE_LENGTH
      The maximum length a modal title can have. (45)
      See Also:
  • Method Details

    • getId

      @Nonnull String getId()
      The custom id of this modal
      Returns:
      The custom id of this modal
      See Also:
    • getTitle

      @Nonnull String getTitle()
      The title of this modal
      Returns:
      The title of this modal
    • getActionRows

      @Nonnull List<ActionRow> getActionRows()
      A List of ActionRows that this modal contains.
      Returns:
      List of ActionRows
    • createCopy

      @Nonnull default Modal.Builder createCopy()
      Creates a new preconfigured Modal.Builder with the same settings used for this modal.
      This can be useful to create an updated version of this modal without needing to rebuild it from scratch.
      Returns:
      The Modal.Builder used to create the modal
    • create

      Creates a new Modal. You must add at least one component to a modal before building it.
      Parameters:
      customId - The custom id for this modal
      title - The title for this modal
      Returns:
      Builder instance to customize this modal further
      Throws:
      IllegalArgumentException -
      • If the provided customId or title are null, empty, or blank
      • If the provided customId is longer than 100 characters
      • If the provided title is longer than 45 characters