重新启动漫游器后如何解决无法正常工作的事件

时间:2019-04-26 13:22:57

标签: discord.js

我对消息响应有问题,我让机器人删除了在通道名appeal上发送的所有消息,然后将其发送到另一个通道名the appeals,并使用:white_check_mark对消息做出反应:并且如果有人用:white_check_mark:对消息做出反应,则该漫游器会自动删除该漫游器,

那是可行的,但是有一个问题,如果我重新启动机器人并对重新启动之前发送的消息做出反应,则机器人不会删除该消息

为什么?

client.on('message', async message => {
   if(message.author.bot) return;
  var muted = message.guild.member(message.author).roles.find(j => j.id === "505763004797812766");

    if (muted && message.channel.id === "563944611693854721"){
      var muted = message.guild.member(message.author).roles.find(j => j.id === "505763004797812766");
      const args = message.content.split(" ").slice(0).join(" ");
      const appeal = new Discord.RichEmbed()
      .setAuthor(message.author.username, message.author.avatarURL)
      .setTitle(message.author.username + " appeal")
      .setColor("RED")
      .addField("Message", args);
      message.guild.channels.find(ch => ch.id === "563966341980225536").send(appeal).then(msg => {
        msg.react('✅');

        client.on('messageReactionAdd', (reaction, user) => {
          if(reaction.emoji.name === "✅") {
            const whitecheckmark = (reaction, user) => reaction.emoji.name === "✅";

            const done = msg.createReactionCollector(whitecheckmark, {time: 60000});

            done.on('collect', r => {
              msg.delete();
              message.guild.channels.find(ch => ch.id === "563966341980225536").send(message.author + " Appeal ended by: " + reaction.users.last())

            })
          }
      });


       })



       message.delete();
       message.channel.overwritePermissions(message.author, {SEND_MESSAGES: false}); 



    }
    else if(!muted && message.channel.id === "563944611693854721"){
      message.channel.overwritePermissions(message.author, {SEND_MESSAGES: true});
    }

   });

2 个答案:

答案 0 :(得分:0)

这是设计使然的事件。解决此问题的唯一方法是,在某些持久队列(例如RabbitMQ或NATS)中对这些事件进行排队,并假设事件在重新启动之前就已经传递给了侦听器。

答案 1 :(得分:0)

通常,“嵌套”事件(即在其他事件中添加侦听器)不是一个好习惯。如果您将messageReactionAdd侦听器本身放置在message事件之外,则它将侦听而无需消息。然后,如果消息已发送且机器人重新启动,则仍会触发反应事件。只需确保确认触发事件的消息确实是应该的即可。