问题描述
我正在尝试为我的服务器制作一个机器人,我正在尝试创建一个命令,您可以在其中向机器人询问一些问题,它会回复,并且您必须提及一个用户,但我不断收到此错误消息: 类型错误:无法读取未定义的属性“用户” 这是我的代码:
await message.channel.awaitMessages(filter,{ max: 1,time: 30000,errors: ['time'] }).then((collected => {
console.log(collected.first().content);
user = collected.mentions.users.first();
(这是我的第一篇文章,如果我做错了什么,很抱歉)
解决方法
使用 async/await
时,promise 将被解析为成功数据或错误。在这里,您使用了 await
关键字并在其末尾应用了 then
。你不应该那样做。这是一个如何使用 async/await
的示例:
const collected = await message.channel.awaitMessages(filter,{ max: 1,time: 30000,errors: ['time'] });
console.log(collected.first().content);
user = collected.mentions.users.first(); // assuming user is already declared
请查看以下参考资料以深入了解更多信息: