【发布时间】:2020-10-18 08:42:42
【问题描述】:
这是我尝试过的代码:
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))
【问题讨论】:
-
如果说can't read property of null,那说明你的dmChannel不存在。如果您查看文档,
author.dmChannel有一个空传播运算符,这意味着它可以是空的 或 DMChannel。您可能需要先创建一个。虽然,您似乎已经使用message.author.send()完成了该操作。有趣的。您确定您的author.send()行工作正常并且作者收到了消息吗?
标签: javascript node.js discord discord.js chatbot