Skip to content

Modals

Overview

Modals are defined by annotating a method with @Modal. The first parameter must always be a ModalEvent.

@Modal("My Modal")
public void onModal(ModalEvent event, @TextInput("Input") String input) { ... }

Text Inputs

You can add text inputs to a modal by adding String parameters annotated with @TextInput. The label and other metadata of the text input is passed to the annotation.

Tip

Just as for command options, the parameter name will be used for the label by default. However, this requires the -parameters compiler flag to be enabled.

Text Inputs can be configured with the following fields:

style

Sets the TextInputStyle. The default value is TextInputStyle.PARAGRAPH.

Example

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput(value = "Reason", style = TextInputStyle.SHORT) String input) { ... }

placeholder

Sets the placeholder of a text input.

Example

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput(value = "Reason", placeholder = "Please give a reason") String input) { ... }

defaultValue

Sets the default value of a text input, which will pre-populate the text input field with the specified String.

Example

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput(value = "Reason", defaultValue = "Rule Violation") String input) { ... }

minValue & maxValue

Sets the minimum and maximum input length of a text input.

Example

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput(value = "Reason", maxValue = 1000) String input) { ... }

required

Sets whether the text input is required. The default value is true.

Example

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput(value = "Reason", required = false) String input) { ... }

Replying with Modals

You can reply to CommandEvents and ComponentEvents with a Modal by calling replyModal(methodName) on the event.

Example

@SlashCommand("ban")
public void onCommand(CommandEvent event, User target) {
    event.replyModal("onModal"); //(1)!
}

@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput("Reason") String input) { ... }
  1. We reference the Modal we want to send via the method name.