(节点:2724)未处理的承诺拒绝警告:类型错误:无法读取未定义的属性'first'



错误:

(node:2724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined
at Object.execute (C:UsersESPDesktopjetSerenityBotsjetMusicCommandsupload.js:20:45)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

代码:

const { MessageEmbed } = require(`discord.js`);
const fs = require('fs')
const request = require(`request`);
module.exports = {
name: 'upload',
description: 'command used to upload .mp3 file',
async execute(message, args){
const HelpEmbed = new MessageEmbed()
.setTitle('Test')
.setColor(0xff0000)
.setDescription('Hello there ESP')
message.channel.send(HelpEmbed);
// Test 
let fileMessage = await message.channel.awaitMessages(m => m.author.id == message.author.id, { max: 1, time: 300000 })
request.get(fileMessage.attachments.first().url)
.on('error', console.error)
.pipe(fs.createWriteStream('./MusicFiles'));
}
}

我想做什么:

我基本上想让它提示一个我已经设置为测试的嵌入,然后等待发送附件,然后下载附件并将其放在文件夹中,任何帮助都将不胜感激,提前感谢。

解析awaitMessages后,它将为您提供消息集合,而不仅仅是一条消息。

您已将max选项设置为1,因此它将只包含一条消息,但这条消息仍在集合中。

试试这样的东西:

fileMessage.first().attachments.first().url

我建议将fileMessage重命名为fileMessages,这样更清楚地表明它是一个集合。

最新更新