aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-04-29 07:18:01 -0400
committerRapptz <[email protected]>2016-04-29 07:18:01 -0400
commit07adb1d5e903695e0dd03369f4a386fb31e04a80 (patch)
tree15ee71231cf77a17e99956d91778f38273fc193e
parentAdd support for server specific nicknames. (diff)
downloaddiscord.py-07adb1d5e903695e0dd03369f4a386fb31e04a80.tar.xz
discord.py-07adb1d5e903695e0dd03369f4a386fb31e04a80.zip
Add ability to change nicknames via Client.change_nickname
-rw-r--r--discord/client.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index aaee8d64..28ad9554 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