Skip to content

Commit

Permalink
feat: implement guild fetch role
Browse files Browse the repository at this point in the history
  • Loading branch information
Snipy7374 committed Nov 24, 2024
1 parent d95db29 commit 4f07877
Show file tree
Hide file tree
Showing 3 changed files with 34 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.
28 changes: 28 additions & 0 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,34 @@ 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: Union[int, Object]) -> 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
Raises
------
HTTPException
Retrieving the role failed.
Returns
-------
:class:`Role`
The retrieved role.
"""
data = await self._state.http.get_role(
self.id,
role_id=(role_id if isinstance(role_id, int) else role_id.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 4f07877

Please sign in to comment.