简体   繁体   English

如何检测对 discord.js 中的消息的多个反应?

[英]How to detect more than one reaction to a message in discord.js?

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.我正在尝试创建一个动态帮助命令,因为用户可以通过对消息做出反应来决定他们想要 go 的“页面”。 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.我尝试将 awaitReactions 方法的最大值设置为大于 1,但是一旦我这样做,它就不会检测到任何反应。 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);
                }
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM