Add labels and string select menus in modals #242
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alongside with the new additions, instead of having "input names" to match with your handlers
@ModalInput, you can now use the native custom ID, note that it must be unique per modal.Example changes:
@Command public class SlashFormat extends ApplicationCommand { private static final String MODAL_NAME = "SlashFormat: formatModal"; - private static final String CODE_INPUT_NAME = "SlashFormat: formatModal codeInput"; + private static final String CODE_INPUT_ID = "SlashFormat: formatModal codeInput"; private final Modals modals; public SlashFormat(Modals modals) { this.modals = modals; } @JDASlashCommand(name = "format") public void onSlashFormat(GuildSlashEvent event) { Modal modal = modals.create("Format your code") .bindTo(MODAL_NAME) .addComponents( - modals.createTextInput(CODE_INPUT_NAME, "Code", TextInputStyle.SHORT) + Label.of( + "Code", + TextInput.create(CODE_INPUT_ID, TextInputStyle.SHORT).build() + ) ) .build(); event.replyModal(modal).queue(); } @ModalHandler(MODAL_NAME) - public void onFormatModal(ModalEvent event, @ModalInput(CODE_INPUT_NAME) String code) { + public void onFormatModal(ModalEvent event, @ModalInput(CODE_INPUT_ID) String code) { // ... } }Breaking changes
nameof@ModalInputhas been updated tocustomIdTextInputBuilderTextInput.create(Java) orTextInput(...) { ... }(Kotlin) instead@ModalInputparametersChanges
ActionComponentparameters now accept a broader type,ICustomIdNew features
Modals#create(...) { ... })Label(...) { ... })TextInput(...) { ... })StringSelectMenu(...) { ... })