aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-04 06:46:19 -0400
committerRapptz <[email protected]>2015-09-04 06:46:19 -0400
commit7ab73bdf454d58214b7a57999ad9a95fbefcf68d (patch)
treeb37264bb486c6af2fa77256afe79e5238a64945d
parentStore email in the client as an attribute. (diff)
downloaddiscord.py-7ab73bdf454d58214b7a57999ad9a95fbefcf68d.tar.xz
discord.py-7ab73bdf454d58214b7a57999ad9a95fbefcf68d.zip
Add support for editing your profile.
-rw-r--r--discord/client.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 86374bb5..33415d2b 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -617,3 +617,33 @@ class Client(object):
url = '{base}/{server}/bans/{user}'.format(base=endpoints.SERVERS, server=server.id, user=user.id)
response = requests.delete(url, headers=self.headers)
+
+ def edit_profile(self, password, **fields):
+ """Edits the current profile of the client.
+
+ All fields except password are optional.
+
+ :param password: The current password for the client's account.
+ :param new_password: The new password you wish to change to.
+ :param email: The new email you wish to change to.
+ :param username: The new username you wish to change to.
+ """
+
+ payload = {
+ 'password': password,
+ 'new_password': fields.get('new_password'),
+ 'email': fields.get('email', self.email),
+ 'username': fields.get('username', self.user.name),
+ 'avatar': self.user.avatar
+ }
+
+ url = '{0}/@me'.format(endpoints.USERS)
+ response = requests.patch(url, headers=self.headers, json=payload)
+
+ if response.status_code == 200:
+ data = response.json()
+ self.token = data['token']
+ self.email = data['email']
+ self.headers['authorization'] = self.token
+ self.user = User(**data)
+