代码之家  ›  专栏  ›  技术社区  ›  jmessore

如何进行discord机器人检查是否正在进行PMed,然后用discord回复所述PM。js?

  •  0
  • jmessore  · 技术社区  · 7 年前

    如何让我的bot检查用户是否正在管理bot,然后让bot响应所述消息?

    到目前为止,我使用的代码,部分工作正常,如“sendMessage和console.log和bot.channels.get等,但它得到了运行该特定部分的正确语句,这就是问题所在,代码:

    // "Help" command for admin assistance
    bot.on('message', (message) => {
    if(message.channel.DMChannel) {
         // Check if the word sent is "help"
         if(message.content.toLowerCase() == 'help') {
            console.log('User ' + member.user.username + ' is requesting assitance. Now alerting staff members!');
            bot.channels.get("397707437781680130").send('**' + member.user.username + '**, is requesting staff assitance. Now alerting staff members!')
            bot.sendMessage('I helped you! A staff member will respond soon!');
         } else {
             bot.sendMessage('You can only ask for help by DM, please type "help" if you need assistance!');
         }
        }
    });    
    

    我很感激你的指点。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Raymond Zhang    7 年前

    不一致js公司 具有内置 channel.type 您可以使用它检查DM通道(也称为PM通道)。

    考虑到这一点,您的代码应该如下所示:

    bot.on('message', (message) => {
       if(message.channel.type == "dm") {
          //what should happen on a dm
       } else {
          //what should happen if the channel is not a dm
       }
    });