use of com.freya02.botcommands.api.components.InteractionConstraints in project BotCommands by freya022.
the class SlashPaginator method replyPaginator.
private void replyPaginator(GuildSlashEvent event, BContext context, InteractionConstraints constraints) {
final PaginatorBuilder builder = new PaginatorBuilder().setConstraints(constraints).useDeleteButton(true).setTimeout(5, TimeUnit.SECONDS, (paginator, message) -> {
paginator.cleanup(context);
// Remove components on timeout
event.getHook().editOriginalComponents().queue();
// Disable all components on timeout, more expensive
// event.getHook()
// .retrieveOriginal()
// .flatMap(m -> m.editMessageComponents(m.getActionRows().stream().map(ActionRow::asDisabled).toList()))
// .queue();
}).setMaxPages(5).setFirstContent(ButtonContent.withString("←")).setPaginatorSupplier((paginator, messageBuilder, components, page) -> {
components.addComponents(1, Components.primaryButton(btnEvt -> {
// Pages starts at 0
paginator.setPage(2);
btnEvt.editMessage(paginator.get()).queue();
}).build(ButtonContent.withEmoji("Go to page 3", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
components.addComponents(1, Components.primaryButton(btnEvt -> {
// Pages starts at 0
paginator.setPage(4);
btnEvt.editMessage(paginator.get()).queue();
}).build(ButtonContent.withEmoji("Go to page 5", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
return new EmbedBuilder().setTitle(// Pages starts at 0
"Page #" + (page + 1)).build();
});
final Paginator paginator = builder.build();
event.reply(paginator.get()).setEphemeral(false).queue();
}
Aggregations