I'm trying to make a bot. When I type ".test" bot waits for a file. After receiving it, he must send me a Discord link from which I can download the same file. But he only refers to the message where I've sent the file.
Before that, I somehow did it and started experimenting something. After that I was unable to get the same result.
There is my code:
module.exports = {
commands: 'test',
callback: (message, arguments, text) => {
const msg_filter = (m) => m.author.id === message.author.id;
message.channel.awaitMessages({ filter: msg_filter, max: 1, time: 60000})
.then((collected) => {
console.log(collected.first())
console.log(collected.first().attachment)
console.log(collected.first().url)
console.log("finish")
}).catch('Error. No respond.')
}
}
Console output:
//First
attachments: Collection(1) [Map] {
'myId' => MessageAttachment {
attachment: 'https://cdn.discordapp.com/attachments/914907287603261510/myId/sample.pdf',
name: 'sample.pdf',
id: 'myId',
size: 3028,
url: 'https://cdn.discordapp.com/attachments/914907287603261510/myId/sample.pdf',
proxyURL: 'https://media.discordapp.net/attachments/914907287603261510/myId/sample.pdf',
height: null,
width: null,
contentType: 'application/pdf',
ephemeral: false
}
},
//Second
undefined
//Third
https://discord.com/channels/901476184532062209/914907287603261510/917789424857780224
collected is a collection that contains every message that got caught by channel.awaitMessages(), so collected.first() is a message.
To access this message's attachments, which is a collection, you would need to do collected.first().attachments (beware of the plural).
With this in mind, you can manage every attachment in a for-each loop, or just get the first attachment via collected.first().attachments.first()