feat: add getGuildBan

This commit is contained in:
Miguel Nogueira 2022-08-23 04:28:35 +01:00
parent b23b32dc4c
commit 43a19fc11f
No known key found for this signature in database
GPG Key ID: 3C6A7E29AF26D370

View File

@ -134,5 +134,24 @@ class Discord
throw new AccountNotLinkedException('Specified website user has not linked their Discord account yet.'); 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);
}
} }