Skip to content

Commit c3c94c6

Browse files
authored
Update discord.php
1 parent 84caf62 commit c3c94c6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

discord.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ function get_user($email = null)
7878
}
7979
}
8080

81+
# A function to give roles to the user
82+
# Note : The bot has to be a member of the server with MANAGE_ROLES permission.
83+
# The bot DOES NOT have to be online, just has to be a bot application and has to be a member of the server.
84+
# This is the basic function which requires few parameters. [ 1: Guild ID, 2: Role ID ]
85+
function give_role($guildid, $roleid)
86+
{
87+
$data = json_encode(array("roles" => array("$roleid")));
88+
$url = $GLOBALS['base_url'] . "/api/guilds/$guildid/members/" . $_SESSION['user_id'] . "/roles/$roleid";
89+
$headers = array('Content-Type: application/json', 'Authorization: Bot ' . $GLOBALS['bot_token']);
90+
$curl = curl_init();
91+
curl_setopt($curl, CURLOPT_URL, $url);
92+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
93+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
94+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
95+
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
96+
$response = curl_exec($curl);
97+
curl_close($curl);
98+
$results = json_decode($response, true);
99+
return $results;
100+
}
101+
81102
# A function to get user guilds | (guilds scope)
82103
function get_guilds()
83104
{
@@ -112,7 +133,7 @@ function get_guild($id)
112133
function get_connections()
113134
{
114135
$url = $GLOBALS['base_url'] . "/api/users/@me/connections";
115-
$headers = array ('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bearer ' . $_SESSION['access_token']);
136+
$headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bearer ' . $_SESSION['access_token']);
116137
$curl = curl_init();
117138
curl_setopt($curl, CURLOPT_URL, $url);
118139
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

0 commit comments

Comments
 (0)