在我不和谐的Webhook中,出现错误:{“嵌入式":["0"]} [英] In my discord webhook, I am getting the error: {"embeds": ["0"]}

查看:88
本文介绍了在我不和谐的Webhook中,出现错误:{“嵌入式":["0"]}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作用于记录某些内容的不和谐Webhook,我已经借助模板(我不擅长php)完成此操作,并且不断收到错误: {"embeds":["0]}

我已经尝试进行研究,但还没有得到任何帮助.介意我进行此测试的混乱情况.

这是我的代码:

 <?php$ url ="https://discordapp.com/api/webhooks/xxx";//审查隐私$ hookObject = json_encode([用户名" =>促销日志","avatar_url" =>"https://cdn.discordapp.com/icons/472520717515096078/60cc7dd2864c95a749516d1213359b67.png","tts" =>错误的,嵌入" =>[[标题" =>促销日志","type" =>富有的",说明" =>","url" =>"http://police.riverside-roleplay.com/promologs.php",颜色" =>hexdec("0099ff"),字段" =>[[名称" =>名称",值" =>"dd","inline" =>错误的],[名称" =>秩",值" =>"$ rank","inline" =>真的],[名称" =>他们的名字",值" =>"dd","inline" =>真的],[名称" =>老等级",值" =>"dd","inline" =>真的],[名称" =>新等级",值" =>"dd","inline" =>真的],[名称" =>原因",值" =>"dd","inline" =>真的],[名称" =>日期",值" =>"dd","inline" =>真的],]]]],JSON_UNESCAPED_SLASHES |JSON_UNESCAPED_UNICODE);$ ch = curl_init();curl_setopt_array($ ch,[CURLOPT_URL =>$ url,CURLOPT_POST =>真的,CURLOPT_POSTFIELDS =>$ hookObject,CURLOPT_HTTPHEADER =>[长度" =>strlen($ hookObject),"Content-Type" =>应用程序/json"]]);$响应= curl_exec($ ch);curl_close($ ch);?> 

这是我使用的模板:

 <?php//将网址替换为您自己的Webhook网址$ url ="https://discordapp.com/api/webhooks/0000000/ABCDEFGH ....";$ hookObject = json_encode([/**嵌入上方显示的一般消息"*/内容" =>一条消息会传到这里",/**消息中显示的用户名*/用户名" =>"MyUsername",/**发件人图片的图片位置*/"avatar_url" =>"https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg",/**是否以文字转语音阅读消息*/"tts" =>错误的,/**文件内容发送以上传文件*///"file" =>",/**嵌入的数组*/嵌入" =>[/**我们的第一个嵌入*/[//设置嵌入标题标题" =>"Google.com",//您嵌入的类型将总是丰富""type" =>富有的",//嵌入说明说明" =>",//您的标题将链接到的URL"url" =>"https://www.google.com/",/*要在嵌入下面显示的时间戳,即发布文章时的IE*必须格式化为ISO8601*/"timestamp" =>"2018-03-10T19:15:45-05:00",//要在嵌入左侧​​使用的整数颜色颜色" =>hexdec("FFFFFF"),//页脚对象页脚" =>[文本" =>"Google TM","icon_url" =>"https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"],//图片对象图像" =>["url" =>"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"],//缩略图对象缩略图" =>["url" =>"https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"],//作者对象作者" =>[名称" =>字母","url" =>"https://www.abc.xyz"],//对象的字段数组字段" =>[//栏位1[名称" =>数据A",值" =>值A","inline" =>错误的],//栏位2[名称" =>数据B",值" =>值B","inline" =>真的],//栏位3[名称" =>数据C",值" =>值C","inline" =>真的]]]]],JSON_UNESCAPED_SLASHES |JSON_UNESCAPED_UNICODE);$ ch = curl_init();curl_setopt_array($ ch,[CURLOPT_URL =>$ url,CURLOPT_POST =>真的,CURLOPT_POSTFIELDS =>$ hookObject,CURLOPT_HTTPHEADER =>[长度" =>strlen($ hookObject),"Content-Type" =>应用程序/json"]]);$响应= curl_exec($ ch);curl_close($ ch);?> 

我的预期结果是嵌入我已设置的字段.我之前有这个,然后将它实现到另一个页面并更改了一些内容,然后就坏了.实际结果是错误 {"embeds":["0"]}

解决方案

您的代码的主要问题似乎是未定义 $ rank ,因为其中没有任何值,因此值"=>"$ rank",引起了该问题,因为Discord期望其中包含一个值.

使用您编写的代码(并将webhook链接替换为功能正常的链接进行测试)最初会产生不同的错误:

{消息":无法发送空消息",代码":50006}

可以通过更改以下位来


对于来自搜索引擎的其他人

最初我遇到了相同的错误,并且找到了原因,但是我这一方面的原因与OP遇到的情况不同.

只要有人从Discord webhook收到以下答复:

  {"embeds":["0"]} 

这可能意味着两件事:

  1. 正文中发送的字段无效
  2. 某些元素已超出限制

对于第一种情况,可以是:

  1. 格式错误:

    • 时间戳 中的格式错误,必须采用 ISO8601 格式
    • color 中的格式错误,必须为十进制,不接受其他任何内容(是的,即使不接受"red" 之类的颜色名称字符串,也要进行转换它们以十进制表示-红色是 16711680 ,您可以使用 SpyColor 这样的网站检查十进制值)
    • icon_url avatar_url url 格式错误,所有这些都必须使用 http:// https://,(另外需要图像的 url ,它可以是 attachment://,只要图像文件也是附加到请求中)
  2. 无效值:

    • 使用意外值,例如为 inline 传递字符串而不是布尔值(可能出于兼容性原因接受了两个字符串:"true" "false" ,但不接受任何其他字符串,并且期望为布尔值)
    • 空值或空值,如果您希望它为空,则不要将其放在第一位,或者使用 _ _ 作为值
    • 未定义的值,请检查所有变量是否均已定义

对于第二种情况,限制如下:

  1. 嵌入标题的限制为256个字符
  2. 嵌入说明的长度为2048个字符
  3. 每个字段的名称限制为256个字符
  4. 每个字段的值限制为1024个字符
  5. 页脚文本的上限为2048个字符
  6. 作者姓名的上限为256个字符
  7. 每封邮件最多可以有25个字段
  8. 每封邮件最多可以嵌入10个
  9. 总字符总数不能超过6000个字符

就我而言,是后者.我设置了电子邮件客户端,以 embeds >中的Discord Webhook的形式发送电子邮件的内容. fields > value ,它传递了整条长长的电子邮件. value 字段的最大字符数限制为1024,但我的电子邮件内容消息中包含1565个字符.

I am making a discord webhook for logging something, I have done it with the help of a template (I'm not good at php) and I keep getting the error: {"embeds": ["0"]}

I have already tried researching it, I haven't gotten back anything helpful. Mind the messiness I did this to test.

Here is my code:

<?php
  $url = "https://discordapp.com/api/webhooks/xxx"; // Censored for privacy

  $hookObject = json_encode([
      "username" => "Promotion Logs",
      "avatar_url" => "https://cdn.discordapp.com/icons/472520717515096078/60cc7dd2864c95a749516d1213359b67.png",
      "tts" => false,
      "embeds" => [
          [
              "title" => "Promotion Logs",
              "type" => "rich",
              "description" => "",
              "url" => "http://police.riverside-roleplay.com/promologs.php",
              "color" => hexdec( "0099ff" ),
              "fields" => [
                  [
                      "name" => "Name",
                      "value" => "dd",
                      "inline" => false
                  ],
                  [
                      "name" => "Rank",
                      "value" => "$rank",
                      "inline" => true
                  ],
                  [
                    "name" => "Their name",
                    "value" => "dd",
                    "inline" => true
                ],
                [
                  "name" => "Old rank",
                  "value" => "dd",
                  "inline" => true
              ],
              [
                "name" => "New rank",
                "value" => "dd",
                "inline" => true
            ],
            [
              "name" => "Reason",
              "value" => "dd",
              "inline" => true
          ],
          [
            "name" => "Date",
            "value" => "dd",
            "inline" => true
        ],
            ]
          ]
      ]

  ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

  $ch = curl_init();

  curl_setopt_array( $ch, [
      CURLOPT_URL => $url,
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => $hookObject,
      CURLOPT_HTTPHEADER => [
          "Length" => strlen( $hookObject ),
          "Content-Type" => "application/json"
      ]
  ]);

  $response = curl_exec( $ch );
  curl_close( $ch );

  ?>

Here is the template I was using:

<?php

// Replace the URL with your own webhook url
$url = "https://discordapp.com/api/webhooks/0000000/ABCDEFGH....";

$hookObject = json_encode([
    /*
     * The general "message" shown above your embeds
     */
    "content" => "A message will go here",
    /*
     * The username shown in the message
     */
    "username" => "MyUsername",
    /*
     * The image location for the senders image
     */
    "avatar_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg",
    /*
     * Whether or not to read the message in Text-to-speech
     */
    "tts" => false,
    /*
     * File contents to send to upload a file
     */
    // "file" => "",
    /*
     * An array of Embeds
     */
    "embeds" => [
        /*
         * Our first embed
         */
        [
            // Set the title for your embed
            "title" => "Google.com",

            // The type of your embed, will ALWAYS be "rich"
            "type" => "rich",

            // A description for your embed
            "description" => "",

            // The URL of where your title will be a link to
            "url" => "https://www.google.com/",

            /* A timestamp to be displayed below the embed, IE for when an an article was posted
             * This must be formatted as ISO8601
             */
            "timestamp" => "2018-03-10T19:15:45-05:00",

            // The integer color to be used on the left side of the embed
            "color" => hexdec( "FFFFFF" ),

            // Footer object
            "footer" => [
                "text" => "Google TM",
                "icon_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
            ],

            // Image object
            "image" => [
                "url" => "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
            ],

            // Thumbnail object
            "thumbnail" => [
                "url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
            ],

            // Author object
            "author" => [
                "name" => "Alphabet",
                "url" => "https://www.abc.xyz"
            ],

            // Field array of objects
            "fields" => [
                // Field 1
                [
                    "name" => "Data A",
                    "value" => "Value A",
                    "inline" => false
                ],
                // Field 2
                [
                    "name" => "Data B",
                    "value" => "Value B",
                    "inline" => true
                ],
                // Field 3
                [
                    "name" => "Data C",
                    "value" => "Value C",
                    "inline" => true
                ]
            ]
        ]
    ]

], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

$ch = curl_init();

curl_setopt_array( $ch, [
    CURLOPT_URL => $url,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $hookObject,
    CURLOPT_HTTPHEADER => [
        "Length" => strlen( $hookObject ),
        "Content-Type" => "application/json"
    ]
]);

$response = curl_exec( $ch );
curl_close( $ch );

?>

My expected results is to make an embed with the fields I have setup. I had this before then I implemented it to a different page and changed a few things, then it was broken. Actual results is the error {"embeds": ["0"]}

解决方案

The main problem with your code appear to be that $rank is undefined, as in there's no value in it, so "value" => "$rank", is causing the problem as Discord is expecting a value in it.

Using the code you wrote (and substituting webhook link with functioning link for testing) initially gave a different error:

{"message": "Cannot send an empty message", "code": 50006}

That could be fixed by changing this bit:

      CURLOPT_HTTPHEADER => [
          "Length" => strlen( $hookObject ),
          "Content-Type" => "application/json"
      ]

into this:

      CURLOPT_HTTPHEADER => [
          "Length" => strlen( $hookObject ),
          "Content-Type: application/json"
      ]

After that bit had been changed, it now indeed gave out the error {"embeds": ["0"]} as you described. After I define some value for $rank at top, your code works again. So the actual problem is really that the value is undefined.

See full file comparison between your original code and the edited code on my Gist: https://gist.github.com/mnh48/a707aec600ac74f4e5d50875fcab5d7c

I put 34.2 as example $rank = 34.2;, and the result:


For anyone else coming from search engine

I initially got the same error and I had found the reason, but the reason on my side is different from what OP encountered.

Whenever anyone get this response from Discord webhook:

{"embeds": ["0"]}

It can mean two different thing:

  1. There is invalid field being sent in the body
  2. The limit has been exceeded for certain element

For the first case, it can be:

  1. formatting error:

    • wrong format in timestamp, it must be in ISO8601 format
    • wrong format in color, it must be in decimal, anything else are not accepted (yes, even colour name string like "red" are not accepted, convert them to decimal -- red is 16711680, you can use site like SpyColor to check the decimal value)
    • wrong format in icon_url, avatar_url, or url, all of them must be in http://, https://, (additionally for url that expects image, it can be attachment:// so long the image file is also attached to the request)
  2. invalid value:

    • using unexpected values, like passing string instead of boolean for inline (there's two strings accepted, probably for compatibility reason: "true" and "false", but any other strings are not accepted, and it's expecting boolean)
    • empty or null value, if you want it to be empty then don't include it in the first place, or use _ _ as the value
    • undefined value, check that all variables are actually defined

For the second case, the limit is as follows:

  1. The limit for embed titles are 256 characters
  2. The limit for embed descriptions are 2048 characters
  3. Each field's name is limited to 256 characters
  4. Each field's value is limited to 1024 characters
  5. The limit for footer text is 2048 characters
  6. The limit for author name is 256 characters
  7. There can be 25 fields maximum per message
  8. There can be 10 embeds maximum per message
  9. Total characters overall must not exceed 6000 characters

In my case, it was the latter. I set my email client to send the content of the email as Discord Webhook in embeds > fields > value, and it was passing the whole long email message. The value field has maximum character limit of 1024 but my email content message had 1565 characters.

这篇关于在我不和谐的Webhook中,出现错误:{“嵌入式":["0"]}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆