【问题标题】:How to detect more than one reaction to a message in discord.js?如何检测对 discord.js 中消息的多个反应?
【发布时间】:2021-06-09 04:10:00
【问题描述】:

我正在尝试创建一个动态帮助命令,从某种意义上说,用户可以通过对消息做出反应来决定他们想去哪个“页面”。我试过这样做,但是,我的代码只检测到第一反应。我尝试将 awaitReactions 方法的最大值设置为大于 1,但是一旦我这样做,它就不会检测到任何反应。这是我的代码:

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);
     }
 }
}

【问题讨论】:

    标签: javascript discord discord.js embed


    【解决方案1】:

    使用了收集器。

                    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);
                    }
                });
    

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 2020-12-03
      • 2021-05-14
      • 2021-11-13
      • 2021-04-15
      • 2020-11-08
      • 1970-01-01
      • 2021-10-12
      • 2021-08-11
      相关资源
      最近更新 更多