diff --git a/app/Helpers/Discord.php b/app/Helpers/Discord.php index c2fa5d5..e8b4741 100644 --- a/app/Helpers/Discord.php +++ b/app/Helpers/Discord.php @@ -134,5 +134,24 @@ class Discord throw new AccountNotLinkedException('Specified website user has not linked their Discord account yet.'); } + /** + * Gets (possible) ban for current user. + * + * @return object|bool Ban object if user is banned. Null + * @throws RequestException + */ + public function getGuildBan(): object|bool + { + $ban = Http::withHeaders([ + 'Authorization' => 'Bot ' . config('services.discord.token') + ])->get(config('services.discord.base_url') . "/guilds/{$this->workingGuild}/bans/{$this->user->discord_user_id}"); + + if ($ban->status() == 404) { + return false; + } + + return ($ban->successful()) ? (object) $ban->json() : $ban->throwIf($ban->status() !== 404); + } + }