@@ -78,6 +78,27 @@ function get_user($email = null)
78
78
}
79
79
}
80
80
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
+
81
102
# A function to get user guilds | (guilds scope)
82
103
function get_guilds ()
83
104
{
@@ -112,7 +133,7 @@ function get_guild($id)
112
133
function get_connections ()
113
134
{
114
135
$ 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 ' ]);
116
137
$ curl = curl_init ();
117
138
curl_setopt ($ curl , CURLOPT_URL , $ url );
118
139
curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
0 commit comments