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: implement Guild.fetch_role #2528

Merged
merged 4 commits into from
Aug 12, 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
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
Loading