Package net.dv8tion.jda.api.modals
Interface Modal
- All Superinterfaces:
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", TextInputStyle.SHORT)
.setPlaceholder("Subject of this ticket")
.setMinLength(10)
.setMaxLength(100) // or setRequiredRange(10, 100)
.build();
TextInput body = TextInput.create("body", TextInputStyle.PARAGRAPH)
.setPlaceholder("Your concerns go here")
.setMinLength(30)
.setMaxLength(1000)
.build();
Modal modal = Modal.create("modmail", "Modmail")
.addComponents(Label.of("Subject", subject), Label.of("Body", body))
.build();
event.replyModal(modal).queue();
}
}- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA preconfigured builder for the creation of modals. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum amount of components a Modal can have.static final intThe maximum length a modal custom id can have.static final intThe maximum length a modal title can have. -
Method Summary
Modifier and TypeMethodDescriptionstatic Modal.BuilderCreates a new Modal.default Modal.BuilderCreates a new preconfiguredModal.Builderwith the same settings used for this modal.A List ofcomponentsthat this modal contains.default ModalComponentTreeAModalComponentTreeconstructed fromgetComponents().getId()The custom id of this modalgetTitle()The title of this modalMethods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Field Details
-
MAX_COMPONENTS
static final int MAX_COMPONENTSThe maximum amount of components a Modal can have. (5)- See Also:
-
MAX_ID_LENGTH
static final int MAX_ID_LENGTHThe maximum length a modal custom id can have. (100)- See Also:
-
MAX_TITLE_LENGTH
static final int MAX_TITLE_LENGTHThe maximum length a modal title can have. (45)- See Also:
-
-
Method Details
-
getId
The custom id of this modal- Returns:
- The custom id of this modal
- See Also:
-
getTitle
The title of this modal- Returns:
- The title of this modal
-
getComponents
A List ofcomponentsthat this modal contains.- Returns:
- List of ModalTopLevelComponentUnions
-
getComponentTree
AModalComponentTreeconstructed fromgetComponents().- Returns:
ModalComponentTree
-
createCopy
Creates a new preconfiguredModal.Builderwith 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.Builderused to create the modal
-
create
@Nonnull @CheckReturnValue static Modal.Builder create(@Nonnull String customId, @Nonnull String title) Creates a new Modal. You must add at least one component to a modal before building it.- Parameters:
customId- The custom id for this modaltitle- The title for this modal- Returns:
Builderinstance to customize this modal further- Throws:
IllegalArgumentException-
-