简体   繁体   中英

I am trying to let my discord webhook send message with buttons

So here is my problem.

I am trying to send messages via a discord webhook with buttons in but they don't display or sometimes just give an error code.

The error code basicly says that my JSON stringicicator does not function because of a syntrax error, which is weird because if i send a message without any button components it does function with no problem.

Here is my code:

const request = new XMLHttpRequest();
request.open("POST", "/* the url of the bot */");

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

const params = {
  "embeds": [
    {
      "title": "test",
      "description": "test",
      "color": 65474
    }
  ],
  "components": [
    {
      "type": 1,
      "components": [
        {
          "type": 2,
          "style": 5,
          "label": "kaas",
          "url": "/* url website */"
        }
      ]
    }
  ]


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

您缺少一个}来关闭params对象。

did you solve the problem, our codes are the same and we are in the same situation. i need to add button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM