Discord Webhook发送JSON报400 Bad Request返回embeds.0错误求助
错误产生原因
- 你收到的
"embeds": ["0"]响应含义为:请求中embeds数组下标为0的第一个元素,不符合Discord接口定义的Embed结构校验规则。 - 具体问题出在你直接在embed对象顶层添加了
ticker、exchange等自定义字段,Discord的Embed结构不支持顶层新增未定义字段,所有自定义内容必须放在官方规定的Embed字段范围内。
解决方案
你可以选择以下任意一种方式调整请求体结构:
方式1:使用Embed规范结构展示自定义内容
将自定义字段放入Embed预定义的fields数组中,示例请求体如下:
{ "embeds": [ { "title": "行情触发提醒", "fields": [ { "name": "交易对", "value": "{{ticker}}", "inline": true }, { "name": "交易所", "value": "{{exchange}}", "inline": true }, { "name": "时间周期", "value": "{{interval}}", "inline": true }, { "name": "触发日期", "value": "{{date}}", "inline": true }, { "name": "当前时间", "value": "{{timenow}}", "inline": true } ], "color": 39423 } ] }
方式2:使用纯文本content字段(更简单,无需Embed)
如果不需要卡片排版,可以直接用官方提供的content字段传递内容,示例请求体如下:
{ "content": "交易对:{{ticker}},交易所:{{exchange}},时间周期:{{interval}},触发日期:{{date}},当前时间:{{timenow}}" }
额外注意:所有提交的字段值不能为null或长度为0的空字符串,否则仍会触发校验失败。
内容的提问来源于stack exchange,提问作者NonCoder298
相关产品推荐
相关产品推荐

