【问题标题】:Problem defining typingStart to a specific channel将 typingStart 定义到特定频道的问题
【发布时间】:2021-02-21 01:29:37
【问题描述】:

我试图让我的不和谐机器人仅在用户开始输入定义的频道而不是其他文本频道时才发送此消息。我没有收到任何错误,机器人只是不发送消息。我在这里做错了什么?可以将typingStart 定义到特定频道吗?

const Join2_channel =  "972135774921247676"

bot.on("typingStart", (message , channel) => {
   if (channel.id === Join2_channel) {
      message.send('Type !join');
   }
});

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    typingStart 事件有两个参数; channel(用户开始输入的频道)和user(开始输入的频道),按此顺序。

    在您当前的代码中,您正在检查user.id 是否为972135774921247676,因为这是频道的雪花,所以它不会匹配。你需要更新你的回调函数:

    bot.on("typingStart", (channel, user) => {
      if (channel.id === Join2_channel) {
          channel.send('Type !join');
       }
    });
    

    【讨论】:

    • 没问题!发送消息后,我应该在哪里设置超时功能来暂停机器人,这样他就不会每 7 秒发送一次垃圾邮件?
    • 你的意思是这样延迟消息吗? if (channel.id === Join2_channel) { setTimeout(() => channel.send('Type !join'), 7000); }。或者您可能想使用debounce
    • 感谢您的回复!是的 debounce 听起来是我正在寻找的。我将如何将其应用于我正在尝试做的事情。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2017-03-18
    • 2015-01-10
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 2020-07-31
    • 2022-07-16
    • 1970-01-01
    相关资源
    最近更新 更多