【问题标题】:Discord.js-commando: Stopping all commands if not in a specific channelDiscord.js-commando:如果不在特定频道中,则停止所有命令
【发布时间】:2018-07-14 23:46:30
【问题描述】:

为了测试,我试图停止所有命令,除非在某个频道中。我知道如何专门为每个命令执行此操作,但我试图在主 bot 文件中捕获它,并返回一条消息。到目前为止,我已经尝试了两种方法:

bot.on('command', async m => { (Also tried 'commandmessage')
  console.log('COMMAND');
  if (m.channel != 'bot-testing') {
    return m.channel.send('You can\'t use commands here!');
  }
});

这根本不起作用。然后我尝试了这个:

bot.on('message', async m => {
    m.isDM = (m.guild ? false : true);
    if (m.content[0] != bot.commandPrefix) {
      return;
    } else {
      if (m.channel != 'bot-testing') {
        m.channel.send('You can\'t use commands here!');
      }
    }
});

哪种有效,但不会停止命令。

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    看起来您非常接近 - 您只需在第二个 if-statement 中查看 m.channel.name(使用方法 #2):

    bot.on('message', async m => {
        // ...
        if (m.content[0] != bot.commandPrefix) {
            return;
        } else {
            // [NEW: add .name prop here]
            if (m.channel.name != 'bot-testing') {
                m.channel.send('You can\'t use commands here!');
            }
        }
    });
    

    【讨论】:

    • @William haha​​ 你很好 - 我做了很多 console.log 声明以避免类似的小错误 - 也许这也可以帮助你?
    • 我通常会这样做。实际上,我想我做到了,弄清楚了我需要什么,我想我改变了它。我猜这是一个地狱般的周末。
    猜你喜欢
    • 2018-10-15
    • 2021-08-03
    • 2021-01-13
    • 2020-12-31
    • 2021-08-10
    • 2021-01-17
    • 2018-07-07
    • 2019-08-21
    • 2020-11-21
    相关资源
    最近更新 更多