You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord Webhook返回50006错误,PHP CURL发送消息失败求助

问题解决:Discord Webhook提交空消息错误

你的代码核心问题在于HTTP请求头的格式设置错误:CURLOPT_HTTPHEADER要求传入数组类型参数,而你直接传入了字符串,导致Discord无法正确解析发送的JSON数据,因此判定消息为空。

修正后的代码

$url = 'URL_TO_THE_WEBHOOK'; // 注意补全引号,避免语法错误
$data = json_encode(
    array(
        "content" => "Hi, i am a dummy text. I talk from the website."
    )
);

$ch= curl_init();
// 将HTTP头改为数组格式
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_URL, $url);
// 可移除CURLOPT_CUSTOMREQUEST,设置CURLOPT_POSTFIELDS后会自动使用POST请求方法
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
$response = curl_exec($ch);
$err_status = curl_error($ch);

print_r($data);

if(!empty($response)){
    echo $response;
}else{
    echo $err_status;
}
curl_close($ch);

额外注意事项

  • 确保$url变量被引号包裹,否则会触发PHP语法错误。
  • Discord Webhook的content字段有最大2000字符的限制,过长内容会被拒绝。
  • 若内容包含特殊字符,可在json_encode中添加JSON_UNESCAPED_UNICODE参数保证编码正确。

执行错误返回:
{"content":"Hi, i am a dummy text. I talk from the website."}{"message": "Cannot send an empty message", "code": 50006}

内容的提问来源于stack exchange,提问作者Dorvalla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 16:23:16