Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into deps/ruff-0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Nov 25, 2024
2 parents 0ddfb91 + 62f8630 commit e81c77e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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
------
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

0 comments on commit e81c77e

Please sign in to comment.