- Paginates embeds, but can also have message content
- Index Select Menu and Buttons that can be manually turned off
- Slash Command only support
npm i @justnoby15/discord.js-paginator
- discord.js (Version >= ^14.1.2)
There are simple examples of what the code and actual output may look like. Keep in mind, as of version 0.0.3 of the paginator, Messages as the interaction data aren't handled. This is for users to optimize Discord's slash commands and move away from message commands.
Paginator with Select Menu and Buttons:
const { Paginator, Page } = require('@justnoby15/discord.js-paginator');
const { REST } = require('@discordjs/rest'); // Paginator does not support Message Objects as to adjust everyone to using Discord's suggested Slash Commands.
const { Client, GatewayIntentBits, InteractionType, Routes, EmbedBuilder } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
const commands = [
{
name: 'test',
description: 'test for pro package',
},
];
const rest = new REST({ version: '10' }).setToken('your_token_may_go_here');
(async () => {
try {
await rest.put(Routes.applicationCommands(client.user.id), { body: commands });
console.log('Successfully registered commands.');
} catch (error) {
console.error(error);
}
})();
});
client.on('interactionCreate', async (interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
if (interaction.commandName === "test") {
const pages = [
new Page("Embed 1", new EmbedBuilder().setDescription("One")),
new Page("Embed 2", new EmbedBuilder().setDescription("Two"), "Page #2"),
new Page("Embed 3", new EmbedBuilder().setDescription("Three"), "Page #3")
]
const paginator = new Paginator(interaction, pages, 15, {authorOnly: false});
await paginator.run().catch(err => console.log(err));
}
}
});
client.login('your_token_can_go_here');
Instead of using list of Embeds offered by discord.js, you use a list of Pages from this class.
title: string | null
: Displayed as the placeholder for select Menuembed: EmbedBuilder | null
: A discord.js embedcontent: string | null
: The content of the Page (the message)
const pages = [
new Page("Embed 1", new EmbedBuilder().setDescription("One")),
new Page("Embed 2", new EmbedBuilder().setDescription("Two"), "Page #2")
new Page("Embed 3", new EmbedBuilder().setDescription("Three"), "Page #3")
]
const paginator = new Paginator(..., pages, ...);
setTitle(content: string)
: Sets title of a pagesetEmbed(embed: EmbedBuilder)
: Sets the embed of a pagesetMessageContent(content: string)
: Sets the message content of a page
const pages = [
new Page().setTitle("Embed 1").setEmbed(new EmbedBuilder().setDescription("One")),
new Page().setTitle("Embed 2").setEmbed(new EmbedBuilder().setDescription("Two")).setMessageContent("Page #2"),
new Page().setTitle("Embed 3").setEmbed(new EmbedBuilder().setDescription("Three")).setMessageContent("Page #3")
]
const paginator = new Paginator(..., pages, ...);
interaction: CacheType
: Interaction Objectembeds: Page[] | []
: A list of embeds- Use the Page class
seconds: number
: Seconds for collector timeout
options: Object
: An object holding further paginator optionsoptions.authorOnly: boolean = true
: Whether the Paginator responds to the author or notoptions.useButtons: boolean = true
: Wether the Paginator has buttonsoptions.useSelect: boolean = true
: Whether the Paginator has a select menuoptions.deferReply: boolean = false
: Whether the Paginator defers initial replyoptions.editReply: boolean = false
: Whether the Paginator edits the initial interaction replyoptions.disableAfterTimeout: boolean = true
: Whether the Paginator disables after the timeoutoptions.removeAfterTimeout: boolean = false
: Whether the Paginator removes buttons after the timeoutoptions.deleteAfterTimeout: boolean = false
: Whether the Paginator deletes the message after the timeout
addPages(embeds: Page | Page[])
: Adds to embeds of Paginatorconst pages = [ new Page("Embed 1", new EmbedBuilder().setDescription("One")), new Page("Embed 2", new EmbedBuilder().setDescription("Two"), "Page #2"), new Page("Embed 3", new EmbedBuilder().setDescription("Three"), "Page #3") ] const paginator = new Paginator(interaction, pages, 15).addPages(new Page().setTitle("New Page").setEmbed(new EmbedBuilder().setDescription("Four"))).addPages([new Page().setTitle("Even Newer Page").setEmbed(new EmbedBuilder().setDescription("Five")), new Page().setTitle("Newest Page").setEmbed(new EmbedBuilder().setDescription("Six"))]);
setPages(embeds: Page[])
: Sets embeds of Paginatorconst paginator = new Paginator(interaction).setPages([ new Page("Embed 1", new EmbedBuilder().setDescription("One")), new Page("Embed 2", new EmbedBuilder().setDescription("Two"), "Page #2"), new Page("Embed 3", new EmbedBuilder().setDescription("Three"), "Page #3") ]).setSeconds(15);
setSeconds(seconds: number)
: Sets time of Paginator in secondsconst paginator = new Paginator(interaction, pages).setSeconds(15);
setAuthorOnly(bool: boolean)
: Sets authorOnly of Paginatorconst paginator = new Paginator(interaction, pages, 15).setAuthorOnly(false);
setUseButtons(bool: boolean)
: Sets useButtons of Paginatorconst paginator = new Paginator(interaction, pages, 15).setUseButtons(false);
setUseSelect(bool: boolean)
: Sets useSelect of Paginatorconst paginator = new Paginator(interaction, pages, 15).setUseSelect(false);
setDeferReply(bool: boolean)
: Sets deferReply of Paginatorconst paginator = new Paginator(interaction, pages, 15).setDeferReply(true);
setEditReply(bool: boolean)
: Sets editReply of Paginatorconst paginator = new Paginator(interaction, pages, 15).setEditReply(true);
setDisableAfterTimeout(bool: boolean)
: Sets disableAfterTimeout of Paginatorconst paginator = new Paginator(interaction, pages, 15).setDisableAfterTimeout(false);
setRemoveAfterTimeout(bool: boolean)
: Sets removeAfterTimeout of Paginatorconst paginator = new Paginator(interaction, pages, 15).setRemoveAfterTimeout(true);
setDeleteAfterTimeout(bool: boolean)
: Sets deleteAfterTimeout of Paginatorconst paginator = new Paginator(interaction, pages, 15).setDeleteAfterTimeout(true);
Optimal Method Usage
const paginator = new Paginator(interaction).setPages([...]).setSeconds(15).setAuthorOnly(false);
formatOptions()
: Formats all the values you put into the options parameter. Necessary for Paginator process, however user is not inquired to use this function, the paginator already does it for you.- What does it do exactly? It simply checks for undefined properties and sets them to default.
async compileErrors()
: A function that catches all errors you could have based on your inputs.- Returns a Promise: This is so users could check if there Paginator inputs were wrong before running the bot, but this is not required and NOT recommended, because Paginator does it for you. Though, you can use the script like this now:
const paginator = new Paginator(interaction, pages, 15, {useButtons: false, useSelect: false}); // The options throw Invalid Build error await paginator.compileErrors().catch(err => console.log(err)).then(async () => await paginator.run());
async run()
: The Paginatordata()
: Returns all Paginator Attributes
Data you can access using the Paginator's data()
function.
{
interaction: {
interactionType: InteractionType,
client: Client,
channel: TextBasedChannel,
user: User,
guild: Guild,
command: ApplicationCommand || null,
createdAt: Date,
interactionId: SnowFlake
},
paginator: {
pages: Page[],
time: Number,
message: Message,
authorOnly: Boolean,
useButtons: Boolean,
useSelect: Boolean,
deferReply: Boolean,
editReply: Boolean,
disableAfterTimeout: Boolean,
removeAfterTimeout: Boolean,
deleteAfterTimeout: Boolean,
messageId: Snowflake
}
}
const paginator = new Paginator(interaction, pages, 15);
console.log(paginator.data());
- discord-js
- Toricane's interactions.py/Paginator
- KrazyDeveloper's Discord Paginator Tutorial