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

如何回复发送给bot的DMS?

  •  3
  • Mario  · 技术社区  · 8 年前

    我正试图让我的机器人回复发送给它的任何dm。

    所以我现在有:

    client.on('msg', () => {
      if (msg.channel.DMChannel) {
        msg.reply("You are DMing me now!");
      }
    });
    

    但不幸的是,它没有回复任何dm。

    我想换一个 msg.channel.DMChannel 具有 msg.channel.type == 'dm' 但这不起作用。

    我也试图替换 msg.reply 具有 msg.author.send msg.channel.send 但它们都不起作用。

    任何帮助都将不胜感激。

    谢谢!

    2 回复  |  直到 8 年前
        1
  •  5
  •   Mario    8 年前

    official documentation client.on('msg') client.on('message')

    client.on('message', msg => {
      if (msg.channel.type == "dm") {
        msg.author.send("You are DMing me now!");
        return;
      }
    });
    

        2
  •  1
  •   Woohoojin    8 年前

    client.on('message', async message => {
        if (message.channel.type == 'dm') {
            message.reply("You are DMing me now!");
        }
    });
    

    here