diff options
author | Benji Dial <benji@benjidial.net> | 2024-09-05 21:16:43 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-09-05 21:16:43 -0400 |
commit | 87d07ac5b9a4529199cb3f807e4ceff982c588c2 (patch) | |
tree | 6c7b60df12bec73b65c893ad99308cf1f18e07b1 /discord.py | |
parent | d70bd2d83d68f6d51606b2101c318f6f0ff89c85 (diff) | |
download | bracket-bot-87d07ac5b9a4529199cb3f807e4ceff982c588c2.tar.gz |
new new version
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) |