Images randomly not loading

I have a code to log removed images. However, sometimes the image is displayed correctly, and sometimes it's just not showing in the embed. Here's my code:
for (const attachment of attachments) {
const fileType = attachment.contentType.split('/')[0];

if (fileType == 'image') {
const newAttachment = new AttachmentBuilder(attachment.url, { name: attachment.name });

const imageEmbed = new EmbedBuilder()
.setColor('ff2a2a')
.setImage(`attachment://${newAttachment.name}`)

logChannel.send({ embeds: [imageEmbed], files: [newAttachment] });
}
}
for (const attachment of attachments) {
const fileType = attachment.contentType.split('/')[0];

if (fileType == 'image') {
const newAttachment = new AttachmentBuilder(attachment.url, { name: attachment.name });

const imageEmbed = new EmbedBuilder()
.setColor('ff2a2a')
.setImage(`attachment://${newAttachment.name}`)

logChannel.send({ embeds: [imageEmbed], files: [newAttachment] });
}
}
7 Replies
d.js toolkit
d.js toolkit7mo 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! - Marked as resolved by OP
SantaNuny
SantaNunyOP7mo ago
I also just tried to send the image without putting it into an embed, and it's just an empty one
No description
SantaNuny
SantaNunyOP7mo ago
That's exactly what I've done, isn't it?
monbrey
monbrey7mo ago
I mean, the image has been removed so The url might not be pointing to anything
SantaNuny
SantaNunyOP7mo ago
What I'm confused about is that it does sometimes work, but sometimes there's no image. But there's nothing I can do about this?
treble/luna
treble/luna7mo ago
image might be cached is what im guessing, if an image gets deleted, its gone so unless it is stored on some sort of external host
SantaNuny
SantaNunyOP7mo ago
I'll just remove that feature then. Thanks!

Did you find this page helpful?