From 7d08a07cb99ee9e6aca5202f43eefc91dbb20dde Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 16 Dec 2015 00:14:58 -0500 Subject: [PATCH] Fix issue with roles being passed in being strings. Client.add_roles and Client.remove_roles would dispatch to the Client.replace_roles function. However, replace_roles expects Role objects while the dispatching involved string IDs. So as a result this needed another layer of dispatch into a _replace_roles function to do the actual call that all three of them dispatch to. --- discord/client.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/discord/client.py b/discord/client.py index f95c834f5..b23082cf2 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1967,6 +1967,19 @@ class Client: yield from utils._verify_successful_response(response) yield from response.release() + @asyncio.coroutine + def _replace_roles(self, member, *roles): + url = '{0}/{1.server.id}/members/{1.id}'.format(endpoints.SERVERS, member) + + payload = { + 'roles': list(roles) + } + + r = yield from aiohttp.patch(url, headers=self.headers, data=utils.to_json(payload), loop=self.loop) + log.debug(request_logging_format.format(method='PATCH', response=r)) + yield from utils._verify_successful_response(r) + yield from r.release() + @asyncio.coroutine def add_roles(self, member, *roles): """|coro| @@ -1994,7 +2007,7 @@ class Client: """ new_roles = [role.id for role in itertools.chain(member.roles, roles)] - yield from self.replace_roles(member, *new_roles) + yield from self._replace_roles(member, *new_roles) @asyncio.coroutine def remove_roles(self, member, *roles): @@ -2022,7 +2035,7 @@ class Client: """ new_roles = {role.id for role in member.roles} new_roles = new_roles.difference(roles) - yield from self.replace_roles(member, *new_roles) + yield from self._replace_roles(member, *new_roles) @asyncio.coroutine def replace_roles(self, member, *roles): @@ -2054,16 +2067,8 @@ class Client: Removing roles failed. """ - url = '{0}/{1.server.id}/members/{1.id}'.format(endpoints.SERVERS, member) - - payload = { - 'roles': [role.id for role in roles] - } - - r = yield from aiohttp.patch(url, headers=self.headers, data=utils.to_json(payload), loop=self.loop) - log.debug(request_logging_format.format(method='PATCH', response=r)) - yield from utils._verify_successful_response(r) - yield from r.release() + new_roles = [role.id for role in roles] + yield from self._replace_roles(member, *new_roles) @asyncio.coroutine def create_role(self, server, **fields):