【发布时间】:2018-06-14 05:34:47
【问题描述】:
我通过 OAuth2 URL (https://discordapp.com/api/oauth2/authorize?client_id=398437519408103444&permissions=59392&scope=bot) 验证我的机器人
我想向我的 discord 服务器上的频道发送消息
代码:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://discordapp.com/api/channels/'.$channel_id.'/messages');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
// 'Content-Type: application/json',
'Authorization: Bot '.$this->token
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([
'content' => 'test'
]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($curl);
curl_close ($curl);
var_dump(json_decode($server_output, true));
但反应是:
array(2) {
["code"]=>
int(40001)
["message"]=>
string(12) "Unauthorized"
}
API 链接:https://discordapp.com/developers/docs/resources/channel#create-message
【问题讨论】:
-
阅读 this 或更好,use a library。
-
特别是the docs related to opcodes:
4001 Unknown opcode You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that!