'Connect to DiscordAPI using cURL in PHP

I am trying to PUT and give a member a role using the discord API in PHP cURL. At first, I would use Javascript, but I can't use it because I can see all the tokens in the developer tools source. So these are the code that I wrote to try it out.

$guild = "9731803764710394";
$user = "8731053067618830";
$role = "971391411750588427";

#API
$url = "https://discord.com/api/v8//guilds/${guild}/members/${user}/roles/${role}";
$ch = curl_init ($url);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bot [[TOKEN]]'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array());
$res = curl_exec($ch);
curl_close($ch);

But this code returned an error.

{"message": "Missing Permissions", "code": 50013}

Why is this? I have given Identify authorization.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source