@acegoal07/discordjs-pagination

A simple pagination for Discord.js

Usage no npm install needed!

<script type="module">
  import acegoal07DiscordjsPagination from 'https://cdn.skypack.dev/@acegoal07/discordjs-pagination';
</script>

README

discordjs-pagination

Repository size npm NPM npm (prod) dependency version Libraries.io dependency status for latest release GitHub contributors Monthly Downloads

About   |   Example   |   Make Sure   |   NPM   |   Author


About

Required dependency:

  • discord.js version 13.5.0^

To install use:

npm i @acegoal07/discordjs-pagination

When using the interaction pagination you are able to defer the reply before calling pagination as it supports both deferred and non deferred interaction

If you supply the pagination with less than 2 embeds it will automaticity send the embed without the buttons as a normal embed

If you would are not interested in having custom buttons i would recommend using @acegoal07/djs-pagination-portal which automatically adjusts which buttons to use depending on how many pages you want

Make sure

When calling the pagination make sure it is pagination({ }) without the brackets it won't work

If you want to use either autoDelete or the delete buttons with a interaction pagination if you have already deferred the reply you can't have ephemeral enabled

Example

// Import the @acegoal07/discordjs-pagination package
const pagination = require('@acegoal07/discordjs-pagination');
const { MessageEmbed , MessageButton } = require('discord.js');

// Use MessageEmbed to make pages
// Keep in mind that Embeds should't have their footers set since
// the pagination will overwrite the set footer
const embed1 = new MessageEmbed()
   .setTitle('First Page')
   .setDescription('This is the first page');
const embed2 = new MessageEmbed()
   .setTitle('Second Page')
   .setDescription('This is the second page');

// Use MessageButton to create the buttons
// Do not used link buttons as they don't give an output
const button1 = new MessageButton()
   .setCustomId('previousbtn')
   .setLabel('Previous')
   .setStyle('DANGER');
const button2 = new MessageButton()
   .setCustomId('nextbtn')
   .setLabel('Next')
   .setStyle('SUCCESS');
// The delete button is optional and is not required for
// pagination to work
const button3 = new MessageButton()
   .serCustomId('delbtn')
   .setLabel('Delete')
   .setStyle('DANGER');
const button4 = new MessageButton()
   .serCustomId('lastbtn')
   .setLabel('Last Page')
   .setStyle('Success');
const button5 = new MessageButton()
   .serCustomId('firstbtn')
   .setLabel('First page')
   .setStyle('DANGER');

// Create an array of embeds
pageList = [
    embed1,
    embed2
   // ... Can add as many embeds as you want
];

// Create an array of buttons
buttonList = [
   button1, // Next page button
   button2, // Previous page button
   button3 // Optional delete button (do not include if you do not want it)
];
// To use the first and last buttons use
buttonList = [
   button5, // First page button
   button1, // Next page button
   button2, // Previous page button
   button4, // Last page button
   button3 // Optional delete button (do not include if you do not want it)
];

// Create timeout amount
const timeout = 3000;
// Timeout is how long the collector will listen to the buttons till
// turing off if you do not include the timeout it defaults to 12000
// and the minimum time that can be set is 3000 any lower will result in error

// For messages use
pagination({
   message, // Required
   pageList, // Required
   buttonList, // Required

   timeout, // Optional - if not provided it will default to 12000ms
   replyMessage: true, // Optional - An option to reply to the target message if you do not want
                       // this option remove it from the function call

   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar

   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
});

// For interaction use
pagination({
   interaction, // Required
   pageList, // Required
   buttonList, // Required

   timeout, // Optional - if not provided it will default to 12000ms
   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call  

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar
   
   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
});