Skip to content

Commit e4c592f

Browse files
committed
Added more rate limit handling
1 parent dbb7e3b commit e4c592f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

discord_slash/http.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ async def edit(self, _resp, bot_id, token, message_id="@original"):
4949
req_url = f"https://discord.com/api/v8/webhooks/{bot_id}/{token}/messages/{message_id}"
5050
async with aiohttp.ClientSession() as session:
5151
async with session.patch(req_url, json=_resp) as resp:
52+
if resp.status == 429:
53+
_json = await resp.json()
54+
self.logger.warning(f"We are being rate limited, retrying after {_json['retry_after']} seconds.")
55+
await asyncio.sleep(_json["retry_after"])
56+
return await self.edit(_resp, bot_id, token, message_id)
5257
if not 200 <= resp.status < 300:
5358
raise RequestFailure(resp.status, await resp.text())
5459
return True
@@ -66,6 +71,11 @@ async def delete(self, bot_id, token, message_id="@original"):
6671
req_url = f"https://discord.com/api/v8/webhooks/{bot_id}/{token}/messages/{message_id}"
6772
async with aiohttp.ClientSession() as session:
6873
async with session.delete(req_url) as resp:
74+
if resp.status == 429:
75+
_json = await resp.json()
76+
self.logger.warning(f"We are being rate limited, retrying after {_json['retry_after']} seconds.")
77+
await asyncio.sleep(_json["retry_after"])
78+
return await self.delete(bot_id, token, message_id)
6979
if not 200 <= resp.status < 300:
7080
raise RequestFailure(resp.status, await resp.text())
7181
return True

0 commit comments

Comments
 (0)