Skip to content

Commit ed25303

Browse files
authored
added webhook, guild and non-200 HTTP support
added webhook and guild fields in access_token raises an error if something goes wrong with HTTP
1 parent d362c74 commit ed25303

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

discordoauth2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def __init__(self, response, token):
6363
self.access = token_instance(response["access_token"], token)
6464
self.expires = response["expires_in"]
6565
self.refresh_token = response["refresh_token"]
66+
67+
try: self.webhook = response["webhook"]
68+
except(KeyError): self.webhook = None
69+
try: self.guild = response["guild"]
70+
except(KeyError): self.guild = None
6671

6772
class discordOauth2():
6873
def __init__(self, client, secret, redirect, token=None):
@@ -80,6 +85,7 @@ def exchange_code(self, token):
8085
'redirect_uri': self.redirect
8186
})
8287
if response.status_code == 429: raise Exception(f"You are being Rate Limited")
88+
elif response.status_code != 200: raise Exception(f"Something went wrong. Status Code: {response.status_code}")
8389
return access_token(response.json(), self.token)
8490

8591
def refresh_token(self, refresh_token):
@@ -90,4 +96,5 @@ def refresh_token(self, refresh_token):
9096
'refresh_token': refresh_token
9197
})
9298
if response.status_code == 429: raise Exception(f"You are being Rate Limited")
99+
elif response.status_code != 200: raise Exception(f"Something went wrong. Status Code: {response.status_code}")
93100
return access_token(response.json(), self.token)

0 commit comments

Comments
 (0)