From 5698cf6df9b34768a59fc1afa3d16038067949aa Mon Sep 17 00:00:00 2001 From: NCPlayz Date: Sat, 8 Jun 2019 22:38:27 +0100 Subject: [PATCH] Implement `Guild.fetch_roles` --- discord/guild.py | 24 ++++++++++++++++++++++++ discord/http.py | 3 +++ 2 files changed, 27 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index b706c9054..a3f36c472 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1521,6 +1521,30 @@ class Guild(Hashable): data = await self._state.http.create_custom_emoji(self.id, name, img, roles=roles, reason=reason) return self._state.store_emoji(self, data) + async def fetch_roles(self): + """|coro| + + Retrieves all :class:`Role` that the guild has. + + .. note:: + + This method is an API call. For general usage, consider :attr:`roles` instead. + + .. versionadded:: 1.3.0 + + Raises + ------- + HTTPException + Retrieving the roles failed. + + Returns + ------- + List[:class:`Role`] + All roles in the guild. + """ + data = await self._state.http.get_roles(self.id) + return [Role(guild=self, state=self._state, data=d) for d in data] + async def create_role(self, *, reason=None, **fields): """|coro| diff --git a/discord/http.py b/discord/http.py index 17ca74dba..79c03db2e 100644 --- a/discord/http.py +++ b/discord/http.py @@ -722,6 +722,9 @@ class HTTPClient: # Role management + def get_roles(self, guild_id): + return self.request(Route('GET', '/guilds/{guild_id}/roles', guild_id=guild_id)) + def edit_role(self, guild_id, role_id, *, reason=None, **fields): r = Route('PATCH', '/guilds/{guild_id}/roles/{role_id}', guild_id=guild_id, role_id=role_id) valid_keys = ('name', 'permissions', 'color', 'hoist', 'mentionable')