Discord-Pagination.JS
Discord-pagination.js is a tool that help you to create embeds and navigate between with reactions.
Install with npm i discord-pagination.js
Exemples
You can use images
const { Pagination } = require('discord-pagination.js')
const Discord = require('discord.js')
const client = new Discord.Client()
client.login('discord token')
const cats = [
"https://cdn.discordapp.com/attachments/509705821517774848/606840346147684361/file.jpg",
"https://cdn.discordapp.com/attachments/509705821517774848/606840405543354378/file.jpg",
"https://cdn.discordapp.com/attachments/509705821517774848/606840482810822678/file.jpg"
]
const embed = new Discord.RichEmbed()
embed.setTitle('A few cat photos for you (Cat #{pageIndex})')
embed.setImage('{content}')
client.on('message', async message => {
if(message.content=="cats") {
const pag = new Pagination()
pag.setClient(client)
pag.setFormat(embed)
pag.setMaxItemsPerPage(1)
pag.setContent(cats)
pag.setTTL(60000) // One minute to view the cats
pag.on('start', async() => {
await pag.message.react('◀')
await pag.message.react('▶')
})
pag.on('end', async() => {
await pag.message.clearReactions()
await pag.message.edit({
embed: {
title:"Cats have disappeared."
}
})
})
pag.on('react', async(user, reaction) => {
if (reaction.name == "▶") {
pag.turn(1)
pag.update()
}
if (reaction.name == "◀") {
pag.turn(-1)
pag.update()
}
})
await pag.build(message.channel)
}
})
Or text
const { Pagination } = require('discord-pagination.js')
const Discord = require('discord.js')
const client = new Discord.Client()
client.login('discord token')
const guilds = [
"foo",
"bar",
"Les Laboratoires JS",
"Discord Server List",
"Pub'O'Matic",
"NaN",
"Koya"
]
const embed = new Discord.RichEmbed()
embed.setTitle('My servers')
embed.setDescription('{content}')
embed.setFooter('Page {pageIndex}/{pagesCount}')
client.on('message', async message => {
if(message.content=="servers") {
const pag = new Pagination()
pag.setClient(client)
pag.setFormat(embed)
pag.setMaxItemsPerPage(3)
pag.setContent(guilds)
// Infinite time
pag.on('start', async() => {
await pag.message.react('◀')
await pag.message.react('▶')
await pag.message.react('⏩')
await pag.message.react('⏪')
})
pag.on('react', async(user, reaction) => {
if (reaction.name == "▶") {
pag.turn(1)
pag.update()
}
if (reaction.name == "◀") {
pag.turn(-1)
pag.update()
}
if(reaction.name == "⏩") {
pag.turn(2)
pag.update()
}
if(reaction.name == "⏪") {
pag.turn(-2)
pag.update()
}
})
await pag.build(message.channel)
}
})
Exemple with cats but using .setEmbeds(Array<Discord.RichEmbed>)
const Discord = require('discord.js')
const client = new Discord.Client()
client.login('token')
const cats = [
"https://cdn.discordapp.com/attachments/509705821517774848/606840346147684361/file.jpg",
"https://cdn.discordapp.com/attachments/509705821517774848/606840405543354378/file.jpg",
"https://cdn.discordapp.com/attachments/509705821517774848/606840482810822678/file.jpg"
]
let embeds = []
for (var i = 0; i < cats.length; i++) {
const embed = new Discord.RichEmbed()
embed.setTitle('A few cat photos for you (Cat #' + (i + 1) + ')')
embed.setImage(cats[i])
embeds.push(embed)
}
client.on('message', async message => {
if (message.content == "cats") {
const pag = new Pagination()
pag.setClient(client)
pag.setMaxItemsPerPage(1)
pag.setEmbeds(embeds)
pag.setTTL(60000) // One minute to view the cats
pag.on('start', async() => {
await pag.message.react('◀')
await pag.message.react('▶')
})
pag.on('end', async() => {
await pag.message.clearReactions()
await pag.message.edit({
embed: {
title: "Cats have disappeared."
}
})
})
pag.on('react', async(user, reaction) => {
if (reaction.name == "▶") {
pag.turn(1)
pag.update()
}
if (reaction.name == "◀") {
pag.turn(-1)
pag.update()
}
})
await pag.build(message.channel)
}
})
If you want to use custom emotes, replace reaction.name
by reaction.id