【问题标题】:bot responds to specific channel discord.jsbot 响应特定频道 discord.js
【发布时间】:2021-04-02 23:45:07
【问题描述】:

如何让机器人只响应我编写命令的特定频道

client.on('message', message => {
    if(message.content.startsWith("hey")) {
        message.channel.send('hello');
    } 
});

【问题讨论】:

    标签: command discord discord.js bots helper


    【解决方案1】:

    一个简单的方法是检查 message.channel.name 与授权频道的名称或频道列表。例如if (message.channel.name === "BotLounge")。有关该频道的其他可用信息,请参阅https://discord.com/developers/docs/resources/channel

    【讨论】:

      【解决方案2】:

      您可以使用message.channel.id,因为该频道具有唯一的ID,或者您可以使用message.channel.name 进行检查,但这不太唯一,您可能会遇到麻烦。

      所以你可以这样做:

      const myChannelId = '0123456789'
      
      client.on('message', message => {
          if(message.channel.id === myChannelId) return;
          if(message.content.startsWith("hey")) {
              message.channel.send('hello');
          } 
      });
      

      【讨论】:

        猜你喜欢
        • 2020-11-21
        • 2019-09-05
        • 2021-06-13
        • 1970-01-01
        • 2021-08-21
        • 2021-06-11
        • 2020-04-04
        • 2016-10-01
        相关资源
        最近更新 更多