From 176d1cccf02eb623c03ed082c428a9c9d2d3f604 Mon Sep 17 00:00:00 2001 From: JustaSqu1d Date: Mon, 12 Aug 2024 14:44:56 -0700 Subject: [PATCH 1/3] feat: implement `Guild.fetch_role` --- discord/guild.py | 24 ++++++++++++++++++++++++ discord/http.py | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index eda67a2e13..047316f15d 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2814,6 +2814,30 @@ async def fetch_roles(self) -> list[Role]: """ data = await self._state.http.get_roles(self.id) return [Role(guild=self, state=self._state, data=d) for d in data] + + async def fetch_role(self, role_id: int) -> Role: + """|coro| + + Retrieves a :class:`Role` that the guild has. + + .. note:: + + This method is an API call. For general usage, consider using :attr:`get_role` instead. + + .. versionadded:: 2.7 + + Returns + ------- + :class:`Role` + The role in the guild with the specified ID. + + Raises + ------ + HTTPException + Retrieving the role failed. + """ + data = await self._state.http.get_role(self.id, role_id) + return Role(guild=self, state=self._state, data=data) async def _fetch_role(self, role_id: int) -> Role: """|coro| diff --git a/discord/http.py b/discord/http.py index 8b3db319e7..7813d20a23 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2048,6 +2048,16 @@ def delete_invite( def get_roles(self, guild_id: Snowflake) -> Response[list[role.Role]]: return self.request(Route("GET", "/guilds/{guild_id}/roles", guild_id=guild_id)) + def get_role(self, guild_id: Snowflake, role_id: Snowflake) -> Response[role.Role]: + return self.request( + Route( + "GET", + "/guilds/{guild_id}/roles/{role_id}", + guild_id=guild_id, + role_id=role_id, + ) + ) + def edit_role( self, guild_id: Snowflake, From 7b09f4e4bf25390ece67f3717c14c7eb22c90bf5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:45:42 +0000 Subject: [PATCH 2/3] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/guild.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 047316f15d..52d2acd783 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2814,7 +2814,7 @@ async def fetch_roles(self) -> list[Role]: """ data = await self._state.http.get_roles(self.id) return [Role(guild=self, state=self._state, data=d) for d in data] - + async def fetch_role(self, role_id: int) -> Role: """|coro| @@ -2823,14 +2823,14 @@ async def fetch_role(self, role_id: int) -> Role: .. note:: This method is an API call. For general usage, consider using :attr:`get_role` instead. - + .. versionadded:: 2.7 Returns ------- :class:`Role` The role in the guild with the specified ID. - + Raises ------ HTTPException From fb8804980eaeb7f4194d6f675eb3e321fc1d3046 Mon Sep 17 00:00:00 2001 From: JustaSqu1d Date: Mon, 12 Aug 2024 14:55:20 -0700 Subject: [PATCH 3/3] docs: add changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ebb0f0528..2e71e51acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ These changes are available on the `master` branch, but have not yet been releas - ⚠️ **This Version Removes Support For Python 3.8** ⚠️ ([#2521](https://github.com/Pycord-Development/pycord/pull/2521)) +### Added + +- Added `Guild.fetch_role` method. + ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) + ## [2.6.0] - 2024-07-09 ### Added