discordjs-button-pagination-v2
v4.0.2
Published
A simple package for pagination using buttons introduced in discord.js v13 that was updates to work with discord.js v14.
Downloads
11
Maintainers
Readme
discordjs-button-pagination-v2
A simple package to paginate discord embeds via discord buttons introduced in discord.js v13.
Versions
discordjs-button-pagination-v2@interaction
[Default]
for slash command interaction.
Installation
Default command: npm install discordjs-button-pagination-v2
Requirements
Node.js 16.6.1 or newer is required along with Discord.js 13.0.0 or newer.
Usage for Interaction (Slash Command)
Basic Bot Example
// Import the discordjs-button-pagination package
const paginationEmbed = require('discordjs-button-pagination-v2');
// Use MessageEmbed to make pages
// Keep in mind that Embeds should't have their footers set since the pagination method sets page info there
const { EmbedBuilder , ButtonBuilder, ButtonStyle} = require('discord.js');
const embed1 = new EmbedBuilder()
.setTitle('First Page')
.setDescription('This is the first page');
const embed2 = new EmbedBuilder()
.setTitle('Second Page')
.setDescription('This is the second page');
const button1 = new ButtonBuilder()
.setCustomId('previousbtn')
.setLabel('Previous')
.setStyle(ButtonStyle.Danger);
const button2 = new ButtonBuilder()
.setCustomId('nextbtn')
.setLabel('Next')
.setStyle(ButtonStyle.Success);
// Create an array of embeds
pages = [
embed1,
embed2,
//....
//embedN
];
//create an array of buttons
buttonList = [
button1,
button2
]
// Call the paginationEmbed method, first three arguments are required
// timeout is the time till the reaction collectors are active, after this you can't change pages (in ms), defaults to 120000
paginationEmbed(interaction, pages, buttonList, timeout);
// There you go, now you have paged embeds
Note
This will not work with buttons whose style is set as 'LINK' as they do not trigger an interaction event. The buttons will auto disable once the the collector ends after the timeout. You must use the following custom ids for it to work. "previousbtn" and "nextbtn"
The collector timer resets after receiving a button interaction.
Preview
First Page
Second Page
Disabled Buttons after collector end