重新启动漫游器后如何解决无法正常工作的事件 [英] how to fix events not working after restarting the bot

查看:67
本文介绍了重新启动漫游器后如何解决无法正常工作的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对消息的响应有问题,我让机器人删除了在频道名称为的中发出的所有消息,并将其发送至另一个频道名称为上诉并使用:white_check_mark:对消息作出反应,如果有人使用:white_check_mark:对消息作出反应,则漫游器会自动删除该漫游器,

i have a problem with the message reaction, i made the bot to delete any message sent on channel names appeal and send it to another channel names the appeals and react to the message with :white_check_mark: and if someone reacted to the message with the :white_check_mark:, the bot will automaticly delete the bot,

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

thats working but there is a problem, if i restarting the bot and reacting to the message sent before the restarting , the bot don't deleting the message

为什么?

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

   });


推荐答案

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

In general, it isn't good practice to "nest" events (that is, add listeners within others). If you place the messageReactionAdd listener outside of the message event on its own, it will listen without needing a message to. Then, if the message is sent and the bot restarts, the reaction event will still be fired. Just make sure to confirm that the message triggering the event is indeed one that should be.

这篇关于重新启动漫游器后如何解决无法正常工作的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆