Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 1

Help showing next/previous page of a reaction menu

Hi,

 

I am using the below code to create a reaction menu in my Discord bot.

 

let pages = ['General Commands Page 1', 'General Command Page 2', 'General Commands Page 3']; 
let page = 1

let embed = new Discord.RichEmbed()
.setColor("#15f153")
.setFooter(`Page ${page} of ${pages.length}`)
.setDescription(pages[page-1])

message.channel.send(embed).then(msg => {

msg.react('⬅').then( r => {
msg.react('➡')

// Filters
const backwardsFilter = (reaction, user) => reaction.emoji.name === '⬅' && user.id === message.author.id;
const forwardsFilter = (reaction, user) => reaction.emoji.name === '➡' && user.id === message.author.id;

const backwards = msg.createReactionCollector(backwardsFilter, {timer: 6000});
const forwards = msg.createReactionCollector(forwardsFilter, {timer: 6000});
 
backwards.on('collect', r => {
if (page === 1) return;
page--;
embed.setDescription(pages[page-1]);
embed.setFooter(`Page ${page} of ${pages.length}`);
msg.edit(embed)

r.remove(r.users.filter(u => u === message.author).first());
})

forwards.on('collect', r => {
if (page === pages.length) return;
page++;
embed.setDescription(pages[page-1]);
embed.setFooter(`Page ${page} of ${pages.length}`);
msg.edit(embed)

r.remove(r.users.filter(u => u === message.author).first());
})
})
})
}
 
The idea is if I had 15 commands set up in my bot the embed message would show a page with 5 commands on, you could then use the left and right reactions to flip through the other pages (each showing a different set of 5 commands).
 
So far it does show the correct descriptions and footers, however, I am unsure how to proceed with adding the actual lists of commands.  I can get the first page to work but how do I then replace that with the correct embed for page 2 etc?