Skip to content

Shane4368/discord.js-paginator

Repository files navigation

discord.js-paginator

Codacy Badge GitHub package.json version GitHub LICENSE Maintenance Docs Build Status

A simple reaction-based paginator for discord.js.

Installation

# For stable
npm i @shane4368/discord.js-paginator

# For development (requires git)
npm i shane4368/discord.js-paginator

Compatibility

This package does not work with discord.js v11 and previous versions. Only discord.js v12 is currently supported.

Examples

See full documentation.

Basic setup

const { Paginator } = require("@shane4368/discord.js-paginator");

const paginator = new Paginator({ userID: message.author.id });

// Log message when destroyed or timed out.
paginator.on("end", console.log);
// Log error when it occurs.
paginator.on("error", console.error);

// {0} - first occurrence will be replaced with current page number.
// {1} - first occurrence will be replaced with total page count.
paginator.addPage("This is the first page.\n\nPage {0}/{1}")
	.addPage("This is the second page.\n\nPage {0}/{1}")
	.addPage("This is the third page.\n\nPage {0}/{1}")
	.addPage("This is the fourth page.\n\nPage {0}/{1}");

// Ensure your function is async before using 'await' keyword.
await paginator.start(message.channel).catch(console.error);

Miscellaneous

// Setting embed template.
paginator.setEmbedTemplate({
	color: 0x00b6eb,
	title: "Constant Title",
	footer: {
		text: "Custom footer format {0}/{1}"
	}
});

// Adding embed pages.
paginator.addPage({ description: "This is the first page." })
	.addPage({ description: "This is the second page." });

// Disabling front, rear and trash emojis.
paginator.setEmojis({ front: null, rear: null, trash: null });
// Overriding defaults for front, rear and trash emojis.
paginator.setEmojis({ front: "👈", rear: "👉", trash: "474075113176825866" });

Notes

  • Place the page number format in the footer text when using an embed. If no footer is present, one will be automatically created.