如何使用收集器添加多个反应 discord.js

How to add multiple reactions with collectors discord.js

我一直遇到一个问题,我一直在尝试弄清楚如何发送一个嵌入,然后让机器人对该嵌入做出反应,如果你对它做出反应,该机器人将 post 另一个嵌入有点像这样,

-代数, (机器人发送嵌入) (机器人对嵌入做出反应) (命令用户点击反应) (机器人 post 另一个嵌入 特定于反应

我真的需要它有多个反应,比如可能有十个,它会反应 1️⃣、2️⃣、3️⃣、4️⃣、5️⃣、6️⃣、7️⃣、8️⃣、9️⃣、

如果可能的话,我需要机器人来做这件事

-代数 (机器人 posts 嵌入) (机器人反应) (用户使用其中一个数字对嵌入作出反应) (机器人 posts 嵌入对应的反应) (机器人反应) (用户反应) (机器人 post 是另一个与之对应的嵌入)

制作几乎无限的链条。

module.exports = {
    name: 'algebra',
    description: 'This is a command that should help you with algebra',
    async execute(message, args, Discord, client){
        let ageEmbed = new Discord.MessageEmbed()
        .setTitle('Algebra! Its pretty damn hard.')
        .addField('So you are just starting off with Algebra and you want to learn the basics, Well no problem just react with 1️⃣')
        .addField('So you want to know about the questions such as "*x* = 21+5, what is *x*?" well no problem just react with 2️⃣')
        .setColor('#FF1493')
      let msg = await message.channel.send(ageEmbed)
      await msg.react('1️⃣');
      await msg.react('2️⃣');
    
    
      const filter_age = (reaction, user) => {
        return reaction.emoji.name === '1️⃣' || '2️⃣' && user.id === message.author.id && !user.bot;
      }
    
      const collector_age = msg.createReactionCollector(filter_age, {
        time: 30000,
        max: 1
      });
    
    
      collector_age.on('collect', async (reaction, user) => {
        if (reaction.emoji.name === '1️⃣') {
          let justbegginingembed = new Discord.MessageEmbed()
          .setDescription(`Just beggining with Algebra..`)
          .addField("This is where just beggining with algebra will be");
          message.channel.send(justbegginingembed)
        } else {
          collector_age.on('collect', async (reaction, user) => {
            if (reaction.emoji.name === '2️⃣') {
              let algebraembed2 = new Discord.MessageEmbed()
              .setDescription('so you want to learn about ....')
              .addField('THIS IS WHERE');
              message.channel.send(algebraembed2)
            }
        })
    }
})}}    

它不起作用,我不知道如何修复它。该机器人甚至 post 有时会嵌入两个。

谢谢。

当您 return 过滤器时,第二个反应将始终 return 正确,因为您没有将它与任何东西进行比较。
要解决此问题,请将 return reaction.emoji.name === '1️⃣' || '2️⃣' && user.id === message.author.id && !user.bot; 替换为 return reaction.emoji.name === '1️⃣' || reaction.emoji.name === '2️⃣' && user.id === message.author.id && !user.bot;

完整示例:

module.exports = {
    name: 'algebra',
    description: 'This is a command that should help you with algebra',
    async execute(message, args, Discord, client){
        let ageEmbed = new Discord.MessageEmbed()
          .setTitle('Algebra! Its pretty damn hard.')
          .addField('So you are just starting off with Algebra and you want to learn the basics, Well no problem just react with 1️⃣')
          .addField('So you want to know about the questions such as "*x* = 21+5, what is *x*?" well no problem just react with 2️⃣')
          .setColor('#FF1493')
        let msg = await message.channel.send(ageEmbed);
        await msg.react('1️⃣');
        await msg.react('2️⃣');
    
    
        const filter_age = (reaction, user) => {
            return reaction.emoji.name === '1️⃣' || reaction.emoji.name === '2️⃣' && user.id === message.author.id && !user.bot;
        }
    
        const collector_age = msg.createReactionCollector(filter_age, {
            time: 30000,
            max: 1
        });
    
    
        collector_age.on('collect', async (reaction, user) => {
            if (reaction.emoji.name === '1️⃣') {
                let justbegginingembed = new Discord.MessageEmbed()
                  .setDescription(`Just beggining with Algebra..`)
                  .addField("This is where just beggining with algebra will be");
                message.channel.send(justbegginingembed)
            } else {
                collector_age.on('collect', async (reaction, user) => {
                    if (reaction.emoji.name === '2️⃣') {
                        let algebraembed2 = new Discord.MessageEmbed()
                          .setDescription('so you want to learn about ....')
                          .addField('THIS IS WHERE');
                        message.channel.send(algebraembed2)
                    }
                });
            }
        });
    }
}