diff options
Diffstat (limited to 'discord/http.py')
| -rw-r--r-- | discord/http.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/discord/http.py b/discord/http.py index dfb11b6d..ae816043 100644 --- a/discord/http.py +++ b/discord/http.py @@ -119,7 +119,6 @@ class HTTPClient: if self.token is not None: headers['Authorization'] = 'Bot ' + self.token if self.bot_token else self.token - # some checking if it's a JSON request if 'json' in kwargs: headers['Content-Type'] = 'application/json' @@ -210,6 +209,20 @@ class HTTPClient: # clean-up just in case yield from r.release() + def get_attachment(self, url): + resp = yield from self._session.get(url) + try: + if resp.status == 200: + return (yield from resp.read()) + elif resp.status == 404: + raise NotFound(resp, 'attachment not found') + elif resp.status == 403: + raise Forbidden(resp, 'cannot retrieve attachment') + else: + raise HTTPException(resp, 'failed to get attachment') + finally: + yield from resp.release() + # state management @asyncio.coroutine |