Search code examples
discordwebhooks

POST Error when using Discord Webhook in Dev Console on discord.com


I am using a piece of JS I saw in an online tutorial to send a webhook to a discord server I own. When I run the code from localhost on my computer it sends the webhook no problem. However, when I paste the same code into the console on a tab with discord open, the code does not run and I receive a POST error 400. It was working a month ago, What am I doing wrong?

Please note the webhook url shown is not real. Below is the JS I am using:

function sendMessage() {
      const request = new XMLHttpRequest();
      request.open("POST", "https://discordapp.com/api/webhooks/676118118082281513/ZS5YcWhurzokBrKX9NgexqtxrJA5Pu2Bo4i7_JsIxC-JIbPBVhSZkcVVukGOro52rnQA");

      request.setRequestHeader('Content-type', 'application/json');

      const params = {
        username: "My Webhook Name",
        avatar_url: "",
        content: "The message to send"
      }

      request.send(JSON.stringify(params));
    }
sendMessage()

Solution

  • Discord made it impossible to send webhooks with their site for security, To Stop Token Grabbers and other hacks.