aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-04-09 21:40:40 -0400
committerRapptz <[email protected]>2016-04-09 21:42:26 -0400
commit29d3f5a886545067a18d6d5e7f540074b86d7959 (patch)
tree4f718797a327be1dbb404b1a9513399253071ac6
parentAdd User.bot attribute to check if a user is a bot account. (diff)
downloaddiscord.py-29d3f5a886545067a18d6d5e7f540074b86d7959.tar.xz
discord.py-29d3f5a886545067a18d6d5e7f540074b86d7959.zip
Allow Client.edit_profile to work with bot accounts.
-rw-r--r--discord/client.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/discord/client.py b/discord/client.py
index 4e6b2c33..b6ba71f4 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -445,6 +445,7 @@ class Client:
def _login_1(self, token):
log.info('logging in using static token')
self.token = token
+ self.email = None
self.headers['authorization'] = 'Bot {}'.format(self.token)
resp = yield from self.session.get(endpoints.ME, headers=self.headers)
yield from resp.release()
@@ -1448,12 +1449,13 @@ class Client:
yield from response.release()
@asyncio.coroutine
- def edit_profile(self, password, **fields):
+ def edit_profile(self, password=None, **fields):
"""|coro|
Edits the current profile of the client.
- All fields except ``password`` are optional.
+ If a bot account is used then the password field is optional,
+ otherwise it is required.
The profile is **not** edited in place.
@@ -1469,7 +1471,8 @@ class Client:
Parameters
-----------
password : str
- The current password for the client's account.
+ The current password for the client's account. Not used
+ for bot accounts.
new_password : str
The new password you wish to change to.
email : str
@@ -1486,6 +1489,8 @@ class Client:
Editing your profile failed.
InvalidArgument
Wrong image format passed for ``avatar``.
+ ClientException
+ Password is required for non-bot accounts.
"""
try:
@@ -1498,26 +1503,37 @@ class Client:
else:
avatar = None
+ not_bot_account = not self.user.bot
+ if not_bot_account and password is None:
+ raise ClientException('Password is required for non-bot accounts.')
+
payload = {
'password': password,
- 'new_password': fields.get('new_password'),
- 'email': fields.get('email', self.email),
'username': fields.get('username', self.user.name),
'avatar': avatar
}
+ if not_bot_account:
+ payload['email'] = fields.get('email', self.email)
+
+ if 'new_password' in fields:
+ payload['new_password'] = fields['new_password']
+
+
r = yield from self.session.patch(endpoints.ME, 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)
data = yield from r.json()
log.debug(request_success_log.format(response=r, json=payload, data=data))
- self.token = data['token']
- self.email = data['email']
- self.headers['authorization'] = self.token
- if self.cache_auth:
- self._update_cache(self.email, password)
+ if not_bot_account:
+ self.token = data['token']
+ self.email = data['email']
+ self.headers['authorization'] = self.token
+
+ if self.cache_auth:
+ self._update_cache(self.email, password)
@asyncio.coroutine
def change_status(self, game=None, idle=False):