From 71f144f686111f11ede86f56beb956bdf4074d22 Mon Sep 17 00:00:00 2001 From: Jakye Date: Thu, 27 Jul 2023 10:05:33 +0300 Subject: [PATCH 1/3] Added getGuildMember method in InteractsWithDiscord.php --- src/Traits/InteractsWithDiscord.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Traits/InteractsWithDiscord.php b/src/Traits/InteractsWithDiscord.php index 509c0c3..fe87ddf 100644 --- a/src/Traits/InteractsWithDiscord.php +++ b/src/Traits/InteractsWithDiscord.php @@ -94,6 +94,25 @@ public function getGuilds(): Collection return collect($response); } + /** + * Get the user's guild member. + * + * @throws RequestException + * @throws Exception + */ + public function getGuildMember(string $guildId): GuildMember|null + { + $accessToken = $this->getAccessToken(); + + if (!$accessToken) { + throw new Exception('The access token is invalid.'); + } + + $response = (new DiscordService())->getGuildMember($accessToken, $guildId); + + return new GuildMember($response); + } + /** * Join a guild. * From a466b4ab019e9e90acc47fcfeebf29c250ec2af4 Mon Sep 17 00:00:00 2001 From: Jakye Date: Thu, 27 Jul 2023 10:09:02 +0300 Subject: [PATCH 2/3] Updated docs --- docs/pages/interacts_with_discord.mdx | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/pages/interacts_with_discord.mdx b/docs/pages/interacts_with_discord.mdx index 88b4d2f..c735105 100644 --- a/docs/pages/interacts_with_discord.mdx +++ b/docs/pages/interacts_with_discord.mdx @@ -121,6 +121,47 @@ try { } ``` +## getGuildMember + + This method will make a request to Discord's API. It is recommended to cache the response. + +```php copy=false +/** +* Returns the user's guild member from Discord's API. +* +* @return Jakyeru\Larascord\Types\GuildMember|null +* @throws Illuminate\Http\Client\RequestException +* @throws Exception +*/ +``` + +### Example +```php showLineNumbers +use \Illuminate\Support\Facades\Log; + +$user = auth()->user(); + +try { + $guildMember = $user->getGuildMember('123456789012345678'); + + Log::info(json_encode($guildMember)); + /* + { + "avatar": null, + "joined_at": "2023-01-04T09:26:07.172000Z", + "nick": "My Server Nickname", + "roles": [ + "1082025544411000832" + ], + "deaf": false, + "mute": false + } + */ + } catch (\Exception $exception) { + Log::error('Something went wrong.'); + } +``` + ## joinGuild The bot's access token must be set in `.env` as `LARASCORD_ACCESS_TOKEN`. From f2faeca92a2c606e6fe0ccec9ecdcf0a5746338a Mon Sep 17 00:00:00 2001 From: Jakye Date: Thu, 27 Jul 2023 10:09:13 +0300 Subject: [PATCH 3/3] Updated version. --- src/LarascordServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LarascordServiceProvider.php b/src/LarascordServiceProvider.php index 71993dc..af40cde 100644 --- a/src/LarascordServiceProvider.php +++ b/src/LarascordServiceProvider.php @@ -11,7 +11,7 @@ class LarascordServiceProvider extends ServiceProvider * * @var string */ - const VERSION = '5.0.4'; + const VERSION = '5.0.5'; /* * Register the application services.