403 forbidden when making a discord webhook post request

Hello! im receiving the issue of my project not able to send messages to a discord webhook, it gives 403 forbidden each try. Here is the code:

const input = document.createElement("input");
input.type = "file";
input.id = "a";
document.body.appendChild(input);

input.onchange = (e) => {
  const file = e.target.files[0];

  const reader = new FileReader();
  reader.readAsText(file, "UTF-8");

  reader.onload = (readerEvent) => {
    const content = readerEvent.target.result; // This is the content of the file
    console.log(content);
    document.getElementById("modStuff").innerHTML =
      "<pre>" + content.slice(0, 500) + "..." + "</pre>";

    const discordWebhookUrl =
      "https://cors-anywhere.herokuapp.com/https://discord.com/api/webhooks/1105692387210182706/ULsoNvS9R3j4xFYVC2RUTvKTng_fL_TNV90Cp_1IPMxGNZxK1TgshtbBQbOYuckhzOuR";

    const payload = {
      content: "New file detected:",
      embeds: [
        {
          title: file.name,
          description: "File content:",
          fields: [
            {
              name: "Content",
              value: content.slice(0, 500) + "...",
            },
          ],
        },
      ],
    };

    fetch(discordWebhookUrl, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest",
      },
      //request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
      body: JSON.stringify(payload),
    })
      .then((response) => {
        console.log("Message sent to Discord!");
      })
      .catch((error) => {
        console.error("Error sending message to Discord:", error);
      });
  };
};

input.click();

I have tried various different methods of doing this, but they all lead to the same error. Im trying to make it send a simple message of “test”, before i actually try to make it send the file as an attachment (if you can do it that would be appreciated).

1 Like

it looks like you now need to go to cors-anywhere and click a button to get access

1 Like

there doesnt seem to be a button located anywhere

ok apparently that cors proxy no longer works, does anyone know of any others?

1 Like

I like this one: https://corsproxy.io/

that one doesnt seem to work for me (returns 404)

Maybe discord blocks it. But for me I could always fetch discord’s webhooks API even without a proxy (I’m using Firefox)

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.