Discord Message Pagination is an addon for Discord.js. It helps you to create paginated messages using slash commands and message components (Buttons) if your content is too long for one message.
Installation
Node.js v16.6.0 or newer is required.
npm install discord-msg-pagination
Optional packages
Usage
Quick start using embed array
import { sendPaginatedEmbed } from 'discord-msg-pagination';
sendPaginatedEmbed(interaction, embeds);
Using a custom function to update message embed dynamically
onPageChange
will be called whenever a button interaction happens.
import { sendPaginatedEmbed } from 'discord-msg-pagination';
function onPageChange(pageNumber, embed) {
return embed
.setTitle(`This is page #${pageNumber}`);
}
sendPaginatedEmbed(interaction, initialEmbed, { onPageChange });
Options
interface Options {
nextLabel?: string,
previousLabel?: string,
time?: number,
style?: ButtonStyle,
onPageChange?: (event: 'next' | 'previous' | string, embed: EmbedBuilder) => EmbedBuilder | Promise<EmbedBuilder>,
content?: string,
components?: ActionRowBuilder<any>[],
restriction?: 'ALL' | 'AUTHOR' | ((member: GuildMember) => boolean | Promise<boolean>),
startIndex?: number,
ephemeral?: boolean
}
Local test
Set your DISCORD_BOT_TOKEN
to your .env
.
cp .env.sample .env
npm run test:bot