I'm trying to create a dynamic help command, in the sense that the users can decide what "page" they would like to go to simply by reacting to the message. I have tried doing this, however, with my code it only detects the first reaction. I have tried setting the max for the awaitReactions method to more than 1, however once I do that it doesn't detect any reaction. Here is my code:
const Discord = require('discord.js');
const fs = require('fs');
module.exports = {
name: 'help',
aliases: ('cmds'),
description: 'Shows you the list of commands.',
usage: 'help',
example: 'help',
async execute(client, message, args, prefix, footer, color, invite, dev, devID, successEmbed, errorEmbed, usageEmbed) {
const helpEmbed = new Discord.MessageEmbed()
.setColor(color)
.setAuthor(`${client.user.username} Discord Bot\n`)
.setDescription('• 📍 Prefix: ``' + prefix + '``\n' +
`• 🔧 Developer: ${dev}\n\n⚙️ - **Panel**\n👮 - **Moderation**\n❔ - **Other**`);
const moderationEmbed = new Discord.MessageEmbed()
.setColor(color)
.setAuthor(`Config\n`)
.setDescription('To get more information about a certain command, use ``' + prefix +
'help [command]``.\n\n•``test``, ``test2``, ``test3``.');
try {
const filter = (reaction, user) => {
return (reaction.emoji.name === '⚙️' || '👮' || '❔') && user.id === message.author.id;
};
message.delete();
message.channel.send(helpEmbed).then(embedMsg => {
embedMsg.react("⚙️")
.then(embedMsg.react("👮"))
.then(embedMsg.react("❔"))
embedMsg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '⚙️') {
embedMsg.edit(helpEmbed);
} else if (reaction.emoji.name === '👮') {
embedMsg.edit(moderationEmbed);
} else if (reaction.emoji.name === '❔') {
message.reply('test.');
}
})
.catch(collected => {
message.reply('didnt work.');
});
});
} catch (e) {
console.log(e.stack);
}
}
}
Used a collector.
const collector = embedMsg.createReactionCollector(filter);
collector.on('collect', (reaction, user) => {
reaction.users.remove(user.id); // remove the reaction
if (reaction.emoji.name === '⚙️') {
embedMsg.edit(helpEmbed);
} else if (reaction.emoji.name === '🛠️') {
embedMsg.edit(utilityEmbed);
} else if (reaction.emoji.name === '👮') {
embedMsg.edit(moderationEmbed);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.