From 07adb1d5e903695e0dd03369f4a386fb31e04a80 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 29 Apr 2016 07:18:01 -0400 Subject: [PATCH] Add ability to change nicknames via Client.change_nickname --- discord/client.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/discord/client.py b/discord/client.py index aaee8d647..28ad95540 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1399,6 +1399,45 @@ class Client: """ yield from self.ws.change_presence(game=game, idle=idle) + @asyncio.coroutine + def change_nickname(self, member, nickname): + """|coro| + + Changes a member's nickname. + + You must have the proper permissions to change someone's + (or your own) nickname. + + Parameters + ---------- + member : :class:`Member` + The member to change the nickname for. + nickname : Optional[str] + The nickname to change it to. ``None`` to remove + the nickname. + + Raises + ------ + Forbidden + You do not have permissions to change the nickname. + HTTPException + Editing the channel failed. + """ + + url = '{0}/{1.server.id}/members/{1.id}'.format(endpoints.SERVERS, member) + + payload = { + # oddly enough, this endpoint requires '' to clear the nickname + # instead of the more consistent 'null', this might change in the + # future, or not. + 'nick': nickname if nickname else '' + } + + r = yield from self.session.patch(url, data=utils.to_json(payload), headers=self.headers) + log.debug(request_logging_format.format(method='PATCH', response=r)) + yield from utils._verify_successful_response(r) + yield from r.release() + # Channel management @asyncio.coroutine