Modals¶
Overview¶
Modals are defined by annotating a method with @Modal
.
The first parameter must always be a ModalEvent
.
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
placeholder¶
Sets the placeholder of a text input.
Example
defaultValue¶
Sets the default value of a text input, which will pre-populate the text input field with the specified String.
Example
minValue & maxValue¶
Sets the minimum and maximum input length of a text input.
Example
required¶
Sets whether the text input is required. The default value is true
.
Example
Replying with Modals¶
You can reply to CommandEvents
and ComponentEvents
with a Modal by calling replyModal(methodName)
on the event.
Example
@Command("ban")
public void onCommand(CommandEvent event, User target) {
event.replyModal("onModal"); //(1)!
}
@Modal("Ban reason")
public void onModal(ModalEvent event, @TextInput("Reason") String input) { ... }
- We reference the Modal we want to send via the method name.
Dynamic Modals¶
Sometimes you want to modify a Modal dynamically at runtime. You can do so by calling
replyModal(methodName, function)
.
If you want to, you can also use the native JDA builder: