diff options
Diffstat (limited to 'discord.py')
-rw-r--r-- | discord.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/discord.py b/discord.py new file mode 100644 index 0000000..bca80e6 --- /dev/null +++ b/discord.py @@ -0,0 +1,31 @@ +import requests +import time + +def session(token): + s = requests.Session() + s.headers.update({'Authorization': f'Bot {token}'}) + return s + +def post(s, endpoint, object): + while True: + response = s.post(f'https://discord.com/api/v10{endpoint}', json=object) + if response.status_code == 200: + return response.json() + if response.status_code == 429: + time.sleep(float(response.json()['retry_after'])) + else: + print(response.status_code) + print(response.text) + exit(2) + +def get(s, endpoint): + while True: + response = s.get(f'https://discord.com/api/v10{endpoint}') + if response.status_code == 200: + return response.json() + if response.status_code == 429: + time.sleep(float(response.json()['retry_after'])) + else: + print(response.status_code) + print(response.text) + exit(2) |