aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Gurela <[email protected]>2016-03-23 11:04:23 -0700
committerRapptz <[email protected]>2016-04-08 21:11:22 -0400
commit7f340f88ad68e19423d73bf28439442071a69702 (patch)
treeddb07979c41da61a5138fcc4d258113bec2aa564
parentGuard against AttributeErrors when clearing cached slot cache. (diff)
downloaddiscord.py-7f340f88ad68e19423d73bf28439442071a69702.tar.xz
discord.py-7f340f88ad68e19423d73bf28439442071a69702.zip
Add support for token login (for bots)
-rw-r--r--discord/client.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 4df163a8..720d887b 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -464,6 +464,24 @@ class Client:
passing status code.
"""
+ if email == "token":
+ log.info('logging in using static token')
+ self.token = password
+ self.headers['authorization'] = 'Bot {}'.format(self.token)
+ resp = yield from self.session.get(endpoints.ME, headers=self.headers)
+ log.debug(request_logging_format.format(method='GET', response=resp))
+
+ if resp.status != 200:
+ yield from resp.release()
+ if resp.status == 400:
+ raise LoginFailure('Improper token has been passed.')
+ else:
+ raise HTTPException(resp, None)
+
+ log.info('token auth returned status code {}'.format(resp.status))
+ self._is_logged_in.set()
+ return
+
# attempt to read the token from cache
if self.cache_auth:
yield from self._login_via_cache(email, password)