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 diff --git a/discord/guild.py b/discord/guild.py index eda67a2e13..52d2acd783 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2815,6 +2815,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,