Error joining discord server
Closed this issue · 0 comments
remsooo commented
Hey, can anyone help? I keep crashing the same error and I don't know what it's caused by
<?php
require __DIR__ . '/vendor/autoload.php';
use Wohali\OAuth2\Client\Provider\Discord;
use RestCord\DiscordClient;
session_start();
$provider = new \Wohali\OAuth2\Client\Provider\Discord([
'clientId' => 'xyz',
'clientSecret' => 'xyz',
'redirectUri' => 'xyz'
]);
if (!isset($_GET['code'])) {
$options = [
'scope' => ['guilds.join']
];
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
try {
$user = $provider->getResourceOwner($token);
$discord_id = $user->getId();
$args = [
'guild.id' => xyz,
'user.id' => intval($discord_id),
'access_token' => $token
];
$client = new DiscordClient([
'token' => 'xyz'
]);
var_dump($client->guild->addGuildMember($args));
} catch (Exception $e) {
exit("Oh dear... $e");
}
}
?>
and Error code
Oh dear... Wohali\OAuth2\Client\Provider\Exception\DiscordIdentityProviderException: 401: Unauthorized in /var/www/html/discord/vendor/wohali/oauth2-discord-new/src/Provider/Exception/DiscordIdentityProviderException.php:47 Stack trace: #0 /var/www/html/discord/vendor/wohali/oauth2-discord-new/src/Provider/Exception/DiscordIdentityProviderException.php(33): Wohali\OAuth2\Client\Provider\Exception\DiscordIdentityProviderException::fromResponse() #1 /var/www/html/discord/vendor/wohali/oauth2-discord-new/src/Provider/Discord.php(110): Wohali\OAuth2\Client\Provider\Exception\DiscordIdentityProviderException::clientException() #2 /var/www/html/discord/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(628): Wohali\OAuth2\Client\Provider\Discord->checkResponse() #3 /var/www/html/discord/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(784): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse() #4 /var/www/html/discord/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(767): League\OAuth2\Client\Provider\AbstractProvider->fetchResourceOwnerDetails() #5 /var/www/html/discord/discord.php(38): League\OAuth2\Client\Provider\AbstractProvider->getResourceOwner() #6 {main}