1+ import asyncio
12import aiohttp
23from ..error import RequestFailure
34
@@ -30,6 +31,10 @@ async def add_slash_command(bot_id,
3031
3132 async with aiohttp .ClientSession () as session :
3233 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 )
3338 if not 200 <= resp .status < 300 :
3439 raise RequestFailure (resp .status , await resp .text ())
3540 return await resp .json ()
@@ -54,6 +59,10 @@ async def remove_slash_command(bot_id,
5459 url += f"/{ cmd_id } "
5560 async with aiohttp .ClientSession () as session :
5661 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 )
5766 if not 200 <= resp .status < 300 :
5867 raise RequestFailure (resp .status , await resp .text ())
5968 return resp .status
@@ -75,6 +84,10 @@ async def get_all_commands(bot_id,
7584 url += "/commands" if not guild_id else f"/guilds/{ guild_id } /commands"
7685 async with aiohttp .ClientSession () as session :
7786 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 )
7891 if not 200 <= resp .status < 300 :
7992 raise RequestFailure (resp .status , await resp .text ())
8093 return await resp .json ()
0 commit comments