Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(guild): implement new fetch role endpoint #1248

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1247.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement the new :meth:`.Guild.fetch_role` API method.
31 changes: 31 additions & 0 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved
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|

Expand Down
5 changes: 5 additions & 0 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Loading