aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-10-17 07:26:58 -0400
committerRapptz <[email protected]>2015-10-17 17:53:55 -0400
commit84e9300a3db5669d9d8e47031d28a4664bfe9213 (patch)
treea05196ca0f5d793deff1593e8481a9f1780eb622
parentDocument Permissions constants and set default permissions to 0. (diff)
downloaddiscord.py-84e9300a3db5669d9d8e47031d28a4664bfe9213.tar.xz
discord.py-84e9300a3db5669d9d8e47031d28a4664bfe9213.zip
Change Client.edit_role to be less stateful.
-rw-r--r--discord/client.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/discord/client.py b/discord/client.py
index 2453fd0c..c73db4de 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -1027,38 +1027,43 @@ class Client(object):
log.debug(request_logging_format.format(response=response, name='accept_invite'))
return is_response_successful(response)
- def edit_role(self, server, role):
+ def edit_role(self, server, role, **fields):
"""Edits the specified :class:`Role` for the entire :class:`Server`.
- To use this you have to edit the role yourself and then pass it
- to this member function. For example: ::
-
- server = message.channel.server
- role = find(lambda r: r.name == 'My Cool Role', server.roles)
- role.name = 'My Not So Cool Role'
- role.permissions.can_kick_members = False
- role.permissions.can_ban_members = False
- client.edit_role(server, role)
-
- Note that you cannot edit the name of the @everyone role as that role is special.
+ .. versionchanged:: 0.8.0
+ Editing now uses keyword arguments instead of editing the :class:`Role` object directly.
:param server: The :class:`Server` the role belongs to.
:param role: The :class:`Role` to edit.
- :return: ``True`` if editing was successful, ``False`` otherwise.
+ :param name: The new role name to change to. (optional)
+ :param permissions: The new :class:`Permissions` to change to. (optional)
+ :param colour: The new :class:`Colour` to change to. (optional) (aliased to color as well)
+ :param hoist: A boolean indicating if the role should be shown separately. (optional)
+ :return: ``True`` if editing was successful, ``False`` otherwise. If editing is successful,
+ the ``role`` parameter will be updated with the changes.
"""
url = '{0}/{1.id}/roles/{2.id}'.format(endpoints.SERVERS, server, role)
+ color = fields.get('color')
+ if color is None:
+ color = fields.get('colour', role.colour)
payload = {
- 'name': role.name,
- 'permissions': role.permissions.value,
- 'color': role.color,
- 'hoist': role.hoist
+ 'name': fields.get('name', role.name),
+ 'permissions': fields.get('permissions', role.permissions).value,
+ 'color': color.value,
+ 'hoist': fields.get('hoist', role.hoist)
}
response = requests.patch(url, json=payload, headers=self.headers)
+ if is_response_successful(response):
+ data = response.json()
+ log.debug(request_success_log.format(name='edit_role', json=payload, response=response, data=data))
+ role.update(**data)
+ return True
+
log.debug(request_logging_format.format(response=response, name='edit_role'))
- return is_response_successful(response)
+ return False
def delete_role(self, server, role):
"""Deletes the specified :class:`Role` for the entire :class:`Server`.