如何通过浏览器控制台向Discord Webhook发送消息。

huangapple go评论77阅读模式
英文:

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

您随时可以查看这个网站以获取帮助。

https://discohook.org/

例如,我尝试了一个示例,并检查了在 Webhook 发送时触发的网络请求,如下所示。

所以可能需要在请求主体中使用 embeds:nullattachments:[]

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

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"
});

huangapple
  • 本文由 发表于 2023年3月23日 07:58:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定