Interface ModalHandler
public interface ModalHandler
Handler for modal (popup form) interactions.
Modals are popup forms that can collect text input from users.
Preferred approach: Use the @ModalHandler annotation directly on methods
in your @Plugin class:
@Plugin(name = "MyPlugin", version = "1.0.0", author = "Author")
public class MyPlugin {
@ModalHandler("myplugin:feedback")
public void handleFeedback(ModalInteractionEvent event) {
String feedback = event.getValue("feedback-input").getAsString();
event.reply("Thanks for your feedback: " + feedback).setEphemeral(true).queue();
}
}
Alternative: Implement this interface and register via InteractionManager:
public class FeedbackModal implements ModalHandler {
@Override
public String getModalIdPrefix() {
return "myplugin:feedback";
}
@Override
public void handle(ModalInteractionEvent event) {
String feedback = event.getValue("feedback-input").getAsString();
event.reply("Thanks for your feedback: " + feedback).setEphemeral(true).queue();
}
}
-
Method Summary
Modifier and TypeMethodDescriptionGet the modal ID prefix this handler responds to.voidhandle(net.dv8tion.jda.api.events.interaction.ModalInteractionEvent event) Handle the modal submission.
-
Method Details
-
getModalIdPrefix
String getModalIdPrefix()Get the modal ID prefix this handler responds to.- Returns:
- the modal ID prefix
-
handle
void handle(net.dv8tion.jda.api.events.interaction.ModalInteractionEvent event) Handle the modal submission.Called when a user submits a modal form. Use
event.getValue("input-id")to get input values.- Parameters:
event- the modal interaction event
-