I’m trying to remove roles from a guild member using PHP and Discord API.
I can add roles to a guild member, but I cannot remove roles from a guild member.
I use the following code template to add roles for guild members.
I assumed that I could swap “PUT” with “DELETE” and it would remove roles from guild members as outlined below.
It’s not working. How can this code be adjusted to remove roles?
$authToken = "bot_token";
$guildid = "guild_id";
$userid = "user_id";
$roleid = "role_id";
$url = "https://discordapp.com/api/v6/guilds/" . $guildid . "/members/" . $userid . "/roles/" . $roleid;
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array(
'Authorization: Bot '.$authToken,
"Content-Length: 0"
),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => 0
));
$response = curl_exec($ch);
//It's possible to output the response at this place for debugging, so remove the comment if needed
/*
print $response;
print "<pre>";
print_r(json_decode($response));
print "</pre>";
*/
curl_close($ch);
Oculus Orbus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.