【问题标题】:Stop client event | Discord JS停止客户端事件 |不和谐 JS
【发布时间】:2021-09-08 22:35:03
【问题描述】:

我想停止客户端 messageReactionAdd 监听事件,但我现在不知道如何。我想做这样的事情:

client.on('messageReactionAdd', (reaction, user) => {

  //Previous code

  if (user.id == "1234567891234567") {
  //Stop listening event/stop messageReactionAdd listening event and do not execute again
  }

})

注意:我不能使用if (user.id == "1234567891234567") return;一开始是因为我需要以前的代码,我不想在最后使用它,因为我只想不再运行这个事件。

谢谢。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    您可以尝试使用EventEmitter#removeListener()EventEmitter#off()

    removeListener() 将您的回调分配给一个变量,以便在删除侦听器时引用

    const callback = (reaction, user) => {
       // Your code...
    };
    
    client.removeListener('messageReactionAdd' callback);
    

    关闭()

    client.off('messageReactionAdd');
    

    【讨论】:

      猜你喜欢
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 2020-12-02
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多