aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-12-16 00:14:58 -0500
committerRapptz <[email protected]>2015-12-16 00:14:58 -0500
commit7d08a07cb99ee9e6aca5202f43eefc91dbb20dde (patch)
treee9ab8bbc1c23d19d2399ba7dc6f464e91e95b39b
parentFix NameError with itertools in client. (diff)
downloaddiscord.py-7d08a07cb99ee9e6aca5202f43eefc91dbb20dde.tar.xz
discord.py-7d08a07cb99ee9e6aca5202f43eefc91dbb20dde.zip
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.
-rw-r--r--discord/client.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/discord/client.py b/discord/client.py
index f95c834f..b23082cf 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -1968,6 +1968,19 @@ class Client:
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):