Reputation: 31
Is it possible, using PHP/Discord API to assign a role to a user? I currently use OAuth2 for my website visitors to register with Discord. I would then later want to assign the registered website users with a role on a discord server when an admin have reviewed their membership, and I've already configured a bot that have been granted the required permissions on the server.
I have been looking at the documents - but unfortunately they do not really give me the dummy-proof guidance I need. https://discordapp.com/developers/docs/resources/guild#modify-guild-member
Could I do this with Curl maybe?
Upvotes: 2
Views: 3053
Reputation: 21
https://discord.com/developers/docs/resources/guild#add-guild-member-role You can make a cURL call to this API-endpoint, passing a bot token who has the MANAGE_ROLES permission. Here is a code snippet:
$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 => "PUT",
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);
Upvotes: 2