From 62f86301d6a6b465d9ee75de6a01ce46782dc0eb Mon Sep 17 00:00:00 2001 From: Snipy7374 <100313469+Snipy7374@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:52:50 +0100 Subject: [PATCH] feat(guild): implement new fetch role endpoint (#1248) Signed-off-by: Snipy7374 <100313469+Snipy7374@users.noreply.github.com> --- changelog/1247.feature.rst | 1 + disnake/guild.py | 31 +++++++++++++++++++++++++++++++ disnake/http.py | 5 +++++ 3 files changed, 37 insertions(+) create mode 100644 changelog/1247.feature.rst diff --git a/changelog/1247.feature.rst b/changelog/1247.feature.rst new file mode 100644 index 0000000000..7058c31bad --- /dev/null +++ b/changelog/1247.feature.rst @@ -0,0 +1 @@ +Implement the new :meth:`.Guild.fetch_role` API method. diff --git a/disnake/guild.py b/disnake/guild.py index 97ea1e80ac..05f47d9720 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -3581,6 +3581,37 @@ async def delete_emoji(self, emoji: Snowflake, *, reason: Optional[str] = None) """ await self._state.http.delete_custom_emoji(self.id, emoji.id, reason=reason) + async def fetch_role(self, role_id: int, /) -> Role: + """|coro| + + Retrieve a :class:`Role`. + + .. note:: + + This method is an API call. For general usage, consider :meth:`get_role` or :attr:`roles` instead. + + .. versionadded:: 2.10 + + Parameters + ---------- + role_id: :class:`int` + The ID of the role to retrieve. + + Raises + ------ + NotFound + The role requested could not be found. + HTTPException + Retrieving the role failed. + + Returns + ------- + :class:`Role` + The retrieved role. + """ + data = await self._state.http.get_role(self.id, role_id=role_id) + return Role(guild=self, state=self._state, data=data) + async def fetch_roles(self) -> List[Role]: """|coro| diff --git a/disnake/http.py b/disnake/http.py index f0d157d671..1569fe5715 100644 --- a/disnake/http.py +++ b/disnake/http.py @@ -1922,6 +1922,11 @@ def delete_invite(self, invite_id: str, *, reason: Optional[str] = None) -> Resp # Role management + 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 get_roles(self, guild_id: Snowflake) -> Response[List[role.Role]]: return self.request(Route("GET", "/guilds/{guild_id}/roles", guild_id=guild_id))