skip to Main Content

I’m trying to make code that can send a message to a discord webhook through a browser console but I can’t get it to work

I tried this, as well as some reddit threads and reading the docs

Edit: I also tried using a referrer and origin header with no success

fetch('https://discord.com/api/webhooks/WEBHOOK_ID/WEBHOOK_TOKEN', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    content: 'hello world'
  })
});

I’m getting a POST 400 error but i cant for the life of me figure out why
(Yes im using an actual URL when i try the code)

POST https://discord.com/api/webhooks/[ID/TOKEN] 400
(anonymous) @ 00a5b07b3b8bf783d65a.js:153
(anonymous) @ VM234:1

{"message": "Invalid request origin", "code": 50067}

2

Answers


  1. Chosen as BEST ANSWER

    Discord doesn't allow webhook requests from their own site for security reasons My best guess is that they dont want people to be able to send discord cookies with a webhook


  2. You can always check this website for help

    https://discohook.org/

    For example I tried one and checked the network request that was fired upon the webhook send was something like this.

    So maybe embeds:null and attachments:[] is required in the body

    fetch("https://discord.com/api/v10/webhooks/id/token", {
      "headers": {
        "accept": "application/json",
        "accept-language": "en",
        "content-type": "application/json",
        "sec-ch-ua": ""Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": ""Linux"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "cross-site",
        "Referrer-Policy": "strict-origin"
      },
      "body": "{"content":"This is a webhook message from the browser","embeds":null,"attachments":[]}",
      "method": "POST"
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search