diff options
| author | Nadir Chowdhury <[email protected]> | 2020-06-28 19:52:32 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-06-28 14:52:32 -0400 |
| commit | b68cbb7a42e13028d3562d4e29a107d0a0cba331 (patch) | |
| tree | b333c19e14657cd41e18a26b181430b5b92e6d9b | |
| parent | Add support for integrations (diff) | |
| download | discord.py-b68cbb7a42e13028d3562d4e29a107d0a0cba331.tar.xz discord.py-b68cbb7a42e13028d3562d4e29a107d0a0cba331.zip | |
Add support for bulk editing role positions
| -rw-r--r-- | discord/guild.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/discord/guild.py b/discord/guild.py index a31acbbe..d97f7bc9 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1765,6 +1765,72 @@ class Guild(Hashable): # TODO: add to cache return role + async def edit_role_positions(self, positions, *, reason=None): + """|coro| + + Bulk edits a list of :class:`Role` in the guild. + + You must have the :attr:`~Permissions.manage_roles` permission to + do this. + + .. versionadded:: 1.4 + + Example: + + .. code-block:: python3 + + positions = { + bots_role: 1, # penultimate role + tester_role: 2, + admin_role: 6 + } + + await guild.edit_role_positions(positions=positions) + + Parameters + ----------- + positions + A :class:`dict` of :class:`Role` to :class:`int` to change the positions + of each given role. + reason: Optional[:class:`str`] + The reason for editing the role positions. Shows up on the audit log. + + Raises + ------- + Forbidden + You do not have permissions to move the roles. + HTTPException + Moving the roles failed. + InvalidArgument + An invalid keyword argument was given. + + Returns + -------- + List[:class:`Role`] + A list of all the roles in the guild. + """ + if not isinstance(positions, dict): + raise InvalidArgument('positions parameter expects a dict.') + + role_positions = [] + for role, position in positions.items(): + + payload = { + 'id': role.id, + 'position': position + } + + role_positions.append(payload) + + data = await self._state.http.move_role_position(self.id, role_positions, reason=reason) + roles = [] + for d in data: + role = Role(guild=self, data=d, state=self._state) + roles.append(role) + self._roles[role.id] = role + + return roles + async def kick(self, user, *, reason=None): """|coro| |