Javascript (节点:2724)未处理的PromisejectionWarning:TypeError:无法读取属性';第一';未定义的

Javascript (节点:2724)未处理的PromisejectionWarning:TypeError:无法读取属性';第一';未定义的,javascript,discord,discord.js,Javascript,Discord,Discord.js,错误: (node:2724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined at Object.execute (C:\Users\ESP\Desktop\jetSerenity\Bots\jetMusic\Commands\upload.js:20:45) at processTicksAndRejections (internal/process/

错误:

(node:2724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined
    at Object.execute (C:\Users\ESP\Desktop\jetSerenity\Bots\jetMusic\Commands\upload.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'));
    }
}
代码:

(node:2724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined
    at Object.execute (C:\Users\ESP\Desktop\jetSerenity\Bots\jetMusic\Commands\upload.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'));
    }
}
我想做什么:

(node:2724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined
    at Object.execute (C:\Users\ESP\Desktop\jetSerenity\Bots\jetMusic\Commands\upload.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'));
    }
}
我基本上希望它提示一个我已经设置为测试的嵌入,然后等待发送附件,然后下载附件并将其放入文件夹中,任何帮助都将受到感谢,提前感谢。

解决后,它会为您提供一组消息,而不仅仅是一条消息

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

试着这样做:

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

我建议将
fileMessage
重命名为
fileMessages
,以便更清楚地知道它是一个集合。

错误意味着
fileMessage
没有
附件。谢谢!这似乎已经解决了附件获取URL的问题!但它给了我一些非法的dir错误,我会看看是否可以修复它,:)