【问题标题】:How to add multiple reactions with collectors discord.js如何使用收集器 discord.js 添加多个反应
【发布时间】:2021-06-16 20:42:52
【问题描述】:

我一直有一个问题,我一直试图弄清楚如何发送嵌入,然后让机器人对该嵌入做出反应,如果你对它做出反应,机器人将发布另一个类似这样的嵌入,

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

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

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

-代数 (嵌入机器人帖子) (机器人反应) (用户使用其中一个数字对嵌入做出反应) (机器人帖子嵌入与反应相对应) (机器人反应) (用户反应) (机器人发布了另一个与之对应的嵌入)

制作一条几乎无限的链。

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

它不起作用,我不明白如何解决它。该机器人有时甚至会发布两个嵌入内容。

谢谢。

【问题讨论】:

    标签: node.js discord discord.js embed collectors


    【解决方案1】:

    当您返回过滤器时,第二个反应将始终返回 true,因为您没有将它与任何东西进行比较。
    要解决此问题,请将 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)
                        }
                    });
                }
            });
        }
    }
    

    【讨论】:

    • 谢谢。我一直试图找出这个问题
    猜你喜欢
    • 2020-05-09
    • 2021-08-05
    • 2023-03-18
    • 2020-11-30
    • 1970-01-01
    • 2020-07-06
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多