Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于response discord.js的消息_Discord.js_Bots - Fatal编程技术网

关于response discord.js的消息

关于response discord.js的消息,discord.js,bots,Discord.js,Bots,我一直在尝试让我的机器人回复用户对机器人表情符号的反应,但运气不好,我希望有人能在这里帮助我,我只是一个discord.js的初学者 这是我的代码,我只是需要帮助,当用户做出反应时,机器人会发送一条消息回来 bot.on('message', message => { if(message.author.bot) { if(message.embeds) { const embedMsg = message.embe

我一直在尝试让我的机器人回复用户对机器人表情符号的反应,但运气不好,我希望有人能在这里帮助我,我只是一个discord.js的初学者

这是我的代码,我只是需要帮助,当用户做出反应时,机器人会发送一条消息回来

bot.on('message', message => {
    if(message.author.bot) 
    {
        if(message.embeds)
        {
            const embedMsg = message.embeds.find(msg => msg.title === 'Next step');
            if(embedMsg)
            {
                message.react('708923041928839169')
                .then(reaction => reaction.message.react('708923028846805073'))
                .catch(err => console.error);
            }
        }
        return;
    }

    if(message.content.toLowerCase() === 'done'){
      
        const embed = new Discord.MessageEmbed();
        embed.setTitle('Next step')
        embed.setColor(colors.blue);
        embed.setDescription('Please react to Agree or Disagree');
        message.channel.send(embed)
    }

  });

bot.login(token);

您只需使用
ReactionCollector
即可完成此操作。在上可以很容易地找到这方面的文档,我建议您在询问有关StackOverflow的问题之前,如果不确定如何执行某些操作,请先查看这些文档

下面是一个使用您的代码的示例:

bot.on('message', message => {
    if(message.author.bot) return;

    if(message.content.toLowerCase() === 'done'){
  
        const embed = new Discord.MessageEmbed();
        embed.setTitle('Next step')
        embed.setColor(colors.blue);
        embed.setDescription('Please react to Agree or Disagree');
        message.channel.send(embed).then(embedMsg => {
            embedMsg.react('708923041928839169')
            .then(reaction => embedMsg.react('708923028846805073'))
            .catch(err => console.error);

            const filter = (r, u) => r.emoji.id == '708923041928839169' || r.emoji.id == "708923028846805073";
            const collector = message.createReactionCollector(filter, {time: 60000});
            collector.on('collect', (r, u) => {
               //Put your response to reactions here
               message.channel.send("Reply with something to " + u.tag + " because they reacted with " + r.emoji.name);
            });
        })
    }

});

bot.login(token);
我还移动了你的代码,在其中你将反应添加到嵌入中,因为你这样做是不必要的额外步骤

相关资源:

hey@Cannicide您的示例有效,但对该反应的响应不起作用。您能检查一下吗?@SinKnight道歉,由于我的回答中有一个打字错误,我意外地导致
ReactionCollector
只检查ID为“708923041928839169”的反应,而没有检查ID为“708923028846805073”的反应。我假设这就是问题所在,我已经用更正更新了我的答案。还请注意,此示例设置了60秒的时间限制,因此在发送嵌入后一分钟内将不再出现响应(在收集器的选项中调整
time
,以更改该时间)。