discord.js v12:我如何等待 DM 频道中的消息?

这是我尝试过的代码:

message.author.dmChannel.awaitMessages(msg => {
    console.log(msg.content)
});

但它返回此错误消息:

TypeError: Cannot read property 'awaitMessages' of null

更新代码:

message.author.send("What is your name?")

const filter = m => m.author.id === message.author.id

message.author.dmChannel.awaitMessages(filter)
     .then((collected) => console.log(collected.first().content))

推荐答案

你没有正确使用awaitMessages(),你需要传递一个filter

You're not using awaitMessages() properly, you need to pass a filter

const filter = (m) => m.author.id === message.author.id
message.author.dmChannel.awaitMessages(filter)
  .then((collected) => console.log(collected.first().content))

相关文章