Mehran
Mehran

Reputation: 137

Discord get guild member list with php curl

I am using socialite to get the access token:

return Socialite::driver('discord')
->scopes(['email', 'identify', 'connections', 'guilds', 'rpc.api', 
'guilds.join'])
->redirect();

The call back url is providing me the details, since there is no friend list API call I am trying to get user list of guilds with members detail, for this I use curl:

$authToken ="MYTOKEN";
$url="https://discordapp.com/api/v6/users/@me/guilds";

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL            => $url,
    CURLOPT_HTTPHEADER     => array('Authorization: Bearer '.$authToken),
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_VERBOSE        => 1,
    CURLOPT_SSL_VERIFYPEER => 0,
));
$response = curl_exec($ch);
curl_close($ch); 

The API call works fine and gives me a list of guilds with their id's. For example one of the id's was 431731422857003020, but when I tried to make another API call with curl to get list of members

$url="https://discordapp.com/api/v6/guilds/431731422857003020/members";

It gave me this error: {"code": 0, "message": "401: Unauthorized"}

I am not sure if it is because I should use a different method to get the member list or if I should add a different scope, I searched everywhere, but did not see any proper documentation about discord scopes

Upvotes: 1

Views: 5881

Answers (1)

jarvis394
jarvis394

Reputation: 11

You should set header like that: Authorization: Bot {BOT_TOKEN}

Upvotes: 1

Related Questions