#fetching Cdn file link returns 403 “this content is no longer available”

19 messages · Page 1 of 1 (latest)

granite falcon
#

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.

scarlet nightBOT
#
  • 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!
granite falcon
#

I’m also aware that if the file is older then a day it will return this, hence I added the fetch there for getting the message, which does succeed but then fetching that url also returns 403

Using cf workers if that matters

queen forge
#

Did you console.log the url and check the expiration parameter of it? To validate if it expired yet or not

granite falcon
#

That wouldn’t matter, I made the file like 4 mins before using the command

#

This was the ss

#

17:12 when I used the command

queen forge
#

If what can be done to debug your issue doesn’t matter then your issue doesn’t matter

granite falcon
#

waitWhat 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

#

https://cdn.discordapp.com/attachments/1113717932518813756/1276554628065923082/file.json?ex=66c9f3a4&is=66c8a224&hm=e7c8a4ce653965607063715525694bb1864de98c21a73ba03775078cf1ce341d&

This was the one I gave in ddevs, pretty sure it was that one (guessing it’s nearly expired now)

queen forge
#

If that’s really what your log have you then it‘s an issue on your end and/or your fetch function. Because that url is perfectly valid

granite falcon
#

That’s what I’m saying. Opening it in the browser, fetching it on some test nodejs server, all works. That’s why I’m asking for help because I have no idea what to do. I can share more code if that helps, but it’s all pretty simple

#

The message fetch call also fails

queen forge
#

Sounds like cf workers fetch works differently than you expect it to work tbh. Did you check cf docs?

granite falcon
#

But works for literally everything else...?

#
    {
      "message": [
        true,
        "msg fetch"
      ],
      "level": "log",
      "timestamp": 1724497679462
    },
    {
      "message": [
        "false For fetching json for fetched msg This content is no longer available."
      ],
      "level": "log",
      "timestamp": 1724497679475
    },
    {
      "message": [
        "https://cdn.discordapp.com/attachments/1170841870318972988/1276860532124553267/file.json?ex=66cb1089&is=66c9bf09&hm=a2223d53e586d95124873359feb278fdeba4b11fc4149d6c0c48071744e8877b&"
      ],
      "level": "log",
      "timestamp": 1724497679475
    },
    {
      "message": [
        false,
        403,
        "This content is no longer available."
      ],
      "level": "log",
      "timestamp": 1724497679475
    },
#

all the logs I get

granite falcon
#

All cf docs say is that it’s just the fetch api