1
+ import asyncio
1
2
import aiohttp
2
3
from ..error import RequestFailure
3
4
@@ -30,6 +31,10 @@ async def add_slash_command(bot_id,
30
31
31
32
async with aiohttp .ClientSession () as session :
32
33
async with session .post (url , headers = {"Authorization" : f"Bot { bot_token } " }, json = base ) as resp :
34
+ if resp .status == 429 :
35
+ _json = await resp .json ()
36
+ await asyncio .sleep (_json ["retry_after" ])
37
+ return await add_slash_command (bot_id , bot_token , guild_id , cmd_name , description , options )
33
38
if not 200 <= resp .status < 300 :
34
39
raise RequestFailure (resp .status , await resp .text ())
35
40
return await resp .json ()
@@ -54,6 +59,10 @@ async def remove_slash_command(bot_id,
54
59
url += f"/{ cmd_id } "
55
60
async with aiohttp .ClientSession () as session :
56
61
async with session .delete (url , headers = {"Authorization" : f"Bot { bot_token } " }) as resp :
62
+ if resp .status == 429 :
63
+ _json = await resp .json ()
64
+ await asyncio .sleep (_json ["retry_after" ])
65
+ return await remove_slash_command (bot_id , bot_token , guild_id , cmd_id )
57
66
if not 200 <= resp .status < 300 :
58
67
raise RequestFailure (resp .status , await resp .text ())
59
68
return resp .status
@@ -75,6 +84,10 @@ async def get_all_commands(bot_id,
75
84
url += "/commands" if not guild_id else f"/guilds/{ guild_id } /commands"
76
85
async with aiohttp .ClientSession () as session :
77
86
async with session .get (url , headers = {"Authorization" : f"Bot { bot_token } " }) as resp :
87
+ if resp .status == 429 :
88
+ _json = await resp .json ()
89
+ await asyncio .sleep (_json ["retry_after" ])
90
+ return await remove_slash_command (bot_id , bot_token , guild_id )
78
91
if not 200 <= resp .status < 300 :
79
92
raise RequestFailure (resp .status , await resp .text ())
80
93
return await resp .json ()
0 commit comments