Posted in ddevs too but thought I’d post it here as well
Hey,
I’m trying to make a message context menu command which will read a json file when you use it on that message, however when I get the url to fetch, I get 403 This content is no longer available. I know cdn links expire but I also fetched the message attached for testing purposes and got the same result.
The code
const message = interaction.data.resolved.messages[interaction.data.target_id];
if(
!message.attachments.length ||
message.attachments[0].content_type?.split(';')?.[0] !== "application/json"
) {
await edit({ content: "Please reply to a message that has an attachment"});
return;
}
const url = message.attachments[0].url;
const res = await fetch(url, {
headers: {
"Authorization": "Bot ",
'User-Agent': 'DiscordBot (https://gwapes.com, v1.0.0)'
}
});
const msg = await fetch(`https://discord.com/api/v10/channels/${interaction.channel.id}/messages/${interaction.data.target_id}`, {
headers: {
"Authorization": "Bot " + env.discord_token,
'User-Agent': 'DiscordBot (https://gwapes.com, v1.0.0)'
}
});
console.log(msg.ok, "msg fetch")
if(msg.ok) {
const json = await msg.json() as APIMessage
await fetch(json.attachments[0].url, {
headers: {
'User-Agent': 'DiscordBot (https://gwapes.com, v1.0.0)'
}
})
.then(async (r) => console.log(r.ok + " For fetching json for fetched msg " + await r.text().catch(() => "text failed")))
}
console.log(url);
console.log(res.ok, res.status, await res.text().catch(() => "no"));
console.log(interaction)
if(res.ok) {
const json = await res.json();
console.log(json)
Code is super messy and trimmed below since nothing else is relevant.
what, im literally telling you that it wouldn’t matter because the file was made 6 minutes because I used the command. But sure i logged it, let me go grab it for you