Skip to content

Commit

Permalink
feat: implement Guild.fetch_role (#2528)
Browse files Browse the repository at this point in the history
* feat: implement `Guild.fetch_role`

* style(pre-commit): auto fixes from pre-commit.com hooks

* docs: add changelog entry

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

!crowdin update
  • Loading branch information
JustaSqu1d authored Aug 12, 2024
1 parent dfbe23d commit d8a948b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
10 changes: 10 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d8a948b

Please sign in to comment.