我已经尝试将消息发送到服务器数小时了,但是没有发送出去。 我可以接收某些数据,但是无法发送任何消息,我想知道自己是否做错了什么。
这是我目前的尝试
<?php
class Discord {
public static $instance;
public static $api = 'https://discordapp.com/api/v6/';
public static $auth = 'Authorization: Bot ' . config['bot_token'];
private static function generateInstance($request_url, $fields) {
self::$instance = curl_init();
curl_setopt_array(self::$instance, array(
CURLOPT_URL => $request_url,
CURLOPT_HTTPHEADER => [self::$auth, 'Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POSTFIELDS => $fields
));
$response = curl_exec(self::$instance);
curl_close(self::$instance);
return $response;
}
public static function sendMessage() {
return self::generateInstance(self::$api . '/channels/' . intval(632172270751711247) . '/messages', [
'content' => "Hello"
]);
}
}
响应为:
string(42) "{"message": "Unauthorized", "code": 40001}"