Renewing Embedded Discord Links

I'm currently trying to archive all my own posts, which includes downloading all their embedded files and attachments. I fetch all the channel messages and from what I've done it seems like direct attachments do work; but embeds like a copy/pasted cdn.discordapp.com/attachments/.../.../file.jpg file will not renew. More specifically a link like https://media.discordapp.net/attachments/987627219973210124/1127972112628453449/snapchat.gif which is from the gif selector does show up in my client, but not to my bot because it lacks the signature queries. Is there a way to get them to renew so they can be downloaded?
13 Replies
d.js toolkit
d.js toolkit2mo ago
Sukadia
SukadiaOP2mo ago
the original link is just: https://media.discordapp.net/attachments/987627219973210124/1127972112628453449/snapchat.gif discord populates my client with the signatures: https://media.discordapp.net/attachments/987627219973210124/1127972112628453449/snapchat.gif?ex=68e871a4&is=68e72024&hm=3f9c088c21ba928467feff5f92d977655617a296f09e7b1d3bbb51f0e1f655b6&
Inky
Inky2mo ago
Refetch the message Consider storing your pictures elsewhere. This is intentional design by Discord
Sukadia
SukadiaOP2mo ago
you might need to clarify, they are already fetched are they not? it's because it's a content link that it won't give me the signature that renews it and yes yes the point is to grab them to archive them on my own database edited in a clarifier the messages are fetched from the channel, so i already have their objects and whatnot
Inky
Inky2mo ago
Is the link not in the content?
Sukadia
SukadiaOP2mo ago
yea the link is in the content, so i'm trying to get it from message.embeds as opposed to message.attachments
Inky
Inky2mo ago
What path did you use to extract the image from the embed?
Sukadia
SukadiaOP2mo ago
embed.url and embed.data.url which seem to be the same here's the code, it fails at !res.ok because content doesn't exist:
const embedArrays = Array.from(message.embeds.entries())
for (let embedArray of embedArrays) {
const embed = embedArray[1]
const url = embed.data.url
if (!url) continue
const res = await fetch(url, {method: "HEAD"})
if (!res.ok) {
console.log(`F - Failed to check embed: ${url}`)
continue
}
const contentLength = res.headers.get("Content-Length")
if (!contentLength) {
console.log(`F - URL had no content length: ${url}`)
continue
}
const bytes = parseInt(contentLength)
console.log(`S - ${bytes} ${url} `)
totalEmbedBytes += bytes
}
const embedArrays = Array.from(message.embeds.entries())
for (let embedArray of embedArrays) {
const embed = embedArray[1]
const url = embed.data.url
if (!url) continue
const res = await fetch(url, {method: "HEAD"})
if (!res.ok) {
console.log(`F - Failed to check embed: ${url}`)
continue
}
const contentLength = res.headers.get("Content-Length")
if (!contentLength) {
console.log(`F - URL had no content length: ${url}`)
continue
}
const bytes = parseInt(contentLength)
console.log(`S - ${bytes} ${url} `)
totalEmbedBytes += bytes
}
Inky
Inky2mo ago
Is it not in the embed.image.url? I don’t remember how url embeds are structured
Sukadia
SukadiaOP2mo ago
embed.image.url returns an empty string all the time, even for images that work. embed.url seems to only have the link. maybe it'd be populated if it was bot embeds or something still looking for a solution, i'm thinking it isn't possible. i attempted to attach the URL as an attachment in a new temp message to get it refreshed but that doesn't work. it seems like you can only get the CDN to renew it if it's a direct attachment, not a link (even though the actual client does renew it)
İspik
İspik2mo ago
https://github.com/Sapphire-Discord-Bot/images Sapphire has come up with a solution like this, you could check it out
Sukadia
SukadiaOP2mo ago
gotcha, so i'm just gonna drop it as "not possible" since the links are from other servers. i'll have to save the message links and download them manually from my client

Did you find this page helpful?