0

I am sending a Discord webhook request using Javascript, but I keep getting the following errror: Access to XMLHttpRequest at

'WEBHOOK URL' from origin 'http://discordfastlist.ml' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I know exactly what this is after googling alot, tried all the solutions I found but nothing seemed to work with Discord webhooks.

The code I am using:

var xhr = new XMLHttpRequest();
xhr.open("POST", "this is the webhook URL, I am not showing this in the code but it is there", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    'content': "test",
    'username':'Test Webhook',
}));

1 Answers1

0

You need to be able to negotiate the CORS policy with discord before hand, I think this person had the same trouble with a similar situation. Javascript CORS - No 'Access-Control-Allow-Origin' header is present

What you really need to do is perform the pre flight responses and attach the correct cors-policy to your request as well from your javascript request