From 225acd9cb84fa11e3f4979d5cd1b98ffea6e5f71 Mon Sep 17 00:00:00 2001 From: JoshuaMicallefYBSU <91457812+JoshuaMicallefYBSU@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:50:32 +1000 Subject: [PATCH] Update DiscordAccountCheck.php --- app/Jobs/DiscordAccountCheck.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/app/Jobs/DiscordAccountCheck.php b/app/Jobs/DiscordAccountCheck.php index 5bf15cef..0d3f6a05 100644 --- a/app/Jobs/DiscordAccountCheck.php +++ b/app/Jobs/DiscordAccountCheck.php @@ -224,7 +224,7 @@ public function handle() } } - $rolesToAdd = array_diff($rolesToAdd, $discord_member['roles']); + $discord_roles = array_unique($rolesToAdd); } // Name Format for ZQO Members and Other Members @@ -234,24 +234,15 @@ public function handle() $name = $user->FullName('FLC'); } - // Check if the roles are different between Discord and the DB - $diff1 = array_diff($discord_member['roles'], $rolesToAdd); - $diff2 = array_diff($rolesToAdd, $discord_member['roles']); + + // Update user + $discord->getClient()->patch('guilds/'.env('DISCORD_GUILD_ID').'/members/'.$user->discord_user_id, [ + 'json' => [ + 'nick' => $name, + 'roles' => $discord_roles, + ] + ]); - // Name is same on Discord, as well as roles - if ($name == $discord_member['nick'] && (!empty($diff1) || !empty($diff2))) { - // Update user - $discord->getClient()->patch('guilds/'.env('DISCORD_GUILD_ID').'/members/'.$user->discord_user_id, [ - 'json' => [ - 'nick' => $name, - 'roles' => $rolesToAdd, - ] - ]); - - // Sleep API Check - sleep(2); - - } } else { ## User is NOT in the discord