php - 简单的 PHP 不和谐通知现在响应错误代码 50006
问题描述
我有一个简单的每日 PHP 通知到一个不和谐的 webhook。它已经工作了将近一年,但现在它给我一个错误:
{"message": "Cannot send an empty message", "code": 50006}
$content
在之前创建并填充,并且它不是空的。我在这里替换了真实的用户名和头像链接。
$hookObject = json_encode([
"type" => "rich",
"content" => "**Rotation today**\n\n".$content,
"username" => "avatar",
"avatar_url" => "link to avatar",
"tts" => false,
], 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 );
有谁知道现在可能是什么问题?
解决方案
我昨天也收到了这个错误。我找到了这段代码并且它有效:
//===========================================
// Create new webhook in your Discord channel settings and copy&paste URL
//===========================================
$webhookurl = "YOUR_WEBHOOK_URL";
//===========================================
// Compose message. You can use Markdown
// Message Formatting -- https://discordapp.com/developers/docs/reference#message- formatting
//===========================================
$msg = "Test **message** ";
$json_data = array ('content'=>"$msg");
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
推荐阅读
- logging - Kusto - 嵌套分组
- javascript - 如何在Angular中获取上一个/下一个数组字符串
- batch-file - 如何向回显变量添加新行
- mysql - mysql中的批量更新需要很长时间才能获得24000条记录
- java - java.lang.NoClassDefFoundError: com/sun/istack/Pool
- c# - Winapp 驱动程序中如何进行拖放。
- javascript - 在 JavaScript/Html5 中流式传输和播放通过 TCP 数据包接收的音频
- c++ - 如何通过派生类函数从基类更改向量
- python - 如何在 python selenium 中使用样式属性查找 webelement
- bootstrap-modal - p-日历隐藏在 Angular 7 中 bs-modal 的容器面板下