英文:
How can I send a message to a discord webhook through a browser console
问题
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.
I'm getting a POST 400 error but I can't for the life of me figure out why.
(Yes I'm using an actual URL when I try the code).
POST https://discord.com/api/webhooks/[ID/TOKEN] 400
{"message": "Invalid request origin", "code": 50067}
英文:
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}
答案1
得分: 2
Discord出于安全原因不允许来自其自身站点的Webhook请求。我最好的猜测是他们不希望人们能够通过Webhook发送Discord的cookies。
英文:
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
得分: 1
您随时可以查看这个网站以获取帮助。
例如,我尝试了一个示例,并检查了在 Webhook 发送时触发的网络请求,如下所示。
所以可能需要在请求主体中使用 embeds:null
和 attachments:[]
。
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"
});
英文:
You can always check this website for help
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"
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论