From 87d07ac5b9a4529199cb3f807e4ceff982c588c2 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 5 Sep 2024 21:16:43 -0400 Subject: new new version --- discord.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 discord.py (limited to 'discord.py') 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) -- cgit v1.2.3