Skip to content

Commit

Permalink
added webhook, guild and non-200 HTTP support
Browse files Browse the repository at this point in the history
added webhook and guild fields in access_token

raises an error if something goes wrong with HTTP
  • Loading branch information
treeben77 committed Apr 14, 2022
1 parent d362c74 commit ed25303
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions discordoauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __init__(self, response, token):
self.access = token_instance(response["access_token"], token)
self.expires = response["expires_in"]
self.refresh_token = response["refresh_token"]

try: self.webhook = response["webhook"]
except(KeyError): self.webhook = None
try: self.guild = response["guild"]
except(KeyError): self.guild = None

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

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

0 comments on commit ed25303

Please sign in to comment.