How to get attachments from a message?

Hey, i'm recently having some issues with attachments. I want to get the attachment that an user uploaded and then resend in through the bot. I have this code which used to work, but in the last months it stopped working
let files = msg.attachments.map((obj) => new AttachmentBuilder(obj.proxyURL))
console.log(files)
channel.send({ content: `xxx`, embeds: [Embed], components: [Buttons], files: files });
let files = msg.attachments.map((obj) => new AttachmentBuilder(obj.proxyURL))
console.log(files)
channel.send({ content: `xxx`, embeds: [Embed], components: [Buttons], files: files });
The log from console.log
[
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842175291496/Screenshot_1.png?ex=66a93325&is=66a7e1a5&hm=6c87f01db84a1c96ea
344fa4775eb54ed5542a554f9e896712b7d9cea0c10c91&',
name: undefined,
description: undefined
},
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842527871068/image.png?ex=66a93325&is=66a7e1a5&hm=3056040ffca4396f5d957f522
71659be379dd00a3cc02811ecb0fb70a7257d65&',
name: undefined,
description: undefined
}
]
[
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842175291496/Screenshot_1.png?ex=66a93325&is=66a7e1a5&hm=6c87f01db84a1c96ea
344fa4775eb54ed5542a554f9e896712b7d9cea0c10c91&',
name: undefined,
description: undefined
},
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842527871068/image.png?ex=66a93325&is=66a7e1a5&hm=3056040ffca4396f5d957f522
71659be379dd00a3cc02811ecb0fb70a7257d65&',
name: undefined,
description: undefined
}
]
3 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna4mo ago
Is the message contaning the attachment deleted? aka is this in the messageDelete evemt
Lixeiro Charmoso
Lixeiro CharmosoOP4mo ago
I delete the message right after that ChatGPT suggested me this to get the attachments
const attachments = await Promise.all(
msg.attachments.map(async (obj) => {
const response = await axios.get(obj.proxyURL, { responseType: 'arraybuffer' });
const buffer = Buffer.from(response.data);
return new AttachmentBuilder(buffer, { name: obj.name });
})
);
const attachments = await Promise.all(
msg.attachments.map(async (obj) => {
const response = await axios.get(obj.proxyURL, { responseType: 'arraybuffer' });
const buffer = Buffer.from(response.data);
return new AttachmentBuilder(buffer, { name: obj.name });
})
);
But it works only for images, not for files such as a .zip
Want results from more Discord servers?
Add your server