Skip to content

Commit

Permalink
Merge pull request #355 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
Fix Discord Connecting
  • Loading branch information
JoshuaMicallefYBSU authored Oct 17, 2024
2 parents f548a65 + cbb0cd2 commit a9e1a7c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/Http/Controllers/Community/DiscordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function joinCallbackDiscord(Request $request)
//Get access token using returned code
$http = new Client();

// try {
try {
$response = $http->post('https://discord.com/api/v10/oauth2/token', [
'form_params' => [
'client_id' => env('DISCORD_CLIENT_ID'),
Expand All @@ -255,15 +255,15 @@ public function joinCallbackDiscord(Request $request)
],
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
]);
// } catch (ClientException $e) {
// return redirect()->route('my.index')->with('error-modal', $e->getMessage().'... Unable to get Discord Authorisation Code');
// }
} catch (ClientException $e) {
return redirect()->route('my.index')->with('error-modal', $e->getMessage());
}

$access_token = json_decode($response->getBody(), true)['access_token'];


//Make em join Discord
// try {
try {
$response = (new Client())
->put(
'https://discord.com/api/v10/guilds/'.env('DISCORD_GUILD_ID').'/members/'.$user->discord_user_id,
Expand All @@ -278,13 +278,13 @@ public function joinCallbackDiscord(Request $request)
]
]
);
// } catch (ClientException $e) {
// return redirect()->route('my.index')->with('error-modal', $e->getMessage().'.... Unable to update User Details.');
// }
} catch (ClientException $e) {
return redirect()->route('my.index')->with('error-modal', $e->getMessage());
}


//DM them
$user->notify(new DiscordWelcome());
// $user->notify(new DiscordWelcome()); --- Presently DMs do not work...

$user->member_of_czqo = true;
$user->save();
Expand Down Expand Up @@ -320,6 +320,7 @@ public function unlinkDiscord()
$user->discord_user_id = null;
$user->member_of_czqo = false;
$user->discord_avatar = null;
$user->discord_username = null;

//If they have a Discord avatar, remove it
if ($user->avatar_mode == 2) {
Expand Down

0 comments on commit a9e1a7c

Please sign in to comment.