3

我正在尝试让我的机器人回复发送给它的任何 DM。

所以我目前有这个:

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

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

我试图替换msg.channel.DMChannel为,msg.channel.type == 'dm'但这没有用。

我也尝试替换msg.replymsg.author.sendmsg.channel.send但它们都不起作用。

任何帮助,将不胜感激。

谢谢!

4

2 回答 2

6

官方文档中,我没有看到client.on('msg')仅提及该事件client.on('message')
顺便说一句:

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

刚刚尝试过这个并且没有任何问题。

于 2018-07-31T14:05:10.380 回答
1

您的函数没有收到正确的“msg”对象,试试这个:

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

编辑:我在这里引用了示例代码来得出这个结论。也许此链接将来会对您有所帮助。祝你好运!

于 2018-07-31T13:43:39.117 回答