So in my discord bot, I want to use a command to display all available functions in the game with an embed. And then when the player reacts to the message with arrow reactions, I want the bot to edit the embed and send a next/previous page and vice versa.
My code (the bot work fines but only with this):
const list = [first,second];
const emojiNext = '➡';
const emojiPrevious = '⬅';
const reactionArrow = [emojiPrevious, emojiNext];
const time = 60000; // time limit: 1 min
function getList(i) {
return list[i]()
}
function filter(reaction, user){
return (!user.bot) && (reactionArrow.includes(reaction.emoji.name));
}
function onCollect(emoji, message, i, getList,reaction) {
if (reaction.emoji.name === emojiPrevious) {
const embed = getList(i-1);
if (embed !== undefined) {
message.edit(embed);
i--;
}
} else if (reaction.emoji.name === emojiNext) {
const embed = getList(i+1);
if (embed !== undefined) {
message.edit(embed);
i++;
}
}
return i;
function createCollectorMessage(message, getList) {
let i = 0;
const collector = message.createReactionCollector(filter, { time });
collector.on('collect', reaction => {
i = onCollect(reaction.emoji, message, i, getList);
});
collector.on('end', collected => message.clearReactions());
}
function sendList(channel, getList){
message.channel.send(getList(0))
.then(msg => msg.react(emojiPrevious))
.then(msgReaction => msgReaction.message.react(emojiNext))
.then(msgReaction => createCollectorMessage(msgReaction.message, getList));
}
The first and second are the embeds created using const = new Discord.MessageEmbed
method. The problem is whenever I run the command, the bot would send nothing - and yet the terminal doesn't show any error. I tried all other commands in my bot and all of them seem to work fine except for this. I am very basic in javascript or discord.js so help is very appreciated!