diff --git a/src/discord.py b/src/discord.py index 401849e..5d46d6a 100644 --- a/src/discord.py +++ b/src/discord.py @@ -138,7 +138,7 @@ async def send_to_discord_webhook(data: DiscordMessage, webhook_url: str) -> tup async with aiohttp.ClientSession(headers=header, timeout=aiohttp.ClientTimeout(5.0)) as session: try: result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data)) - rate_limit = None if int(result.headers.get('x-ratelimit-limit')) > 0 else result.headers.get('x-ratelimit-reset-after') + rate_limit = None if int(result.headers.get('x-ratelimit-remaining')) > 0 else result.headers.get('x-ratelimit-reset-after') except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError): logger.exception("Could not send the message to Discord") return 3, None diff --git a/src/msgqueue.py b/src/msgqueue.py index d545ae7..df48613 100644 --- a/src/msgqueue.py +++ b/src/msgqueue.py @@ -47,8 +47,9 @@ class MessageQueue: if status[0] < 2: logger.debug("Sending message succeeded") self._queue.remove(msg) + logger.debug("Current rate limit time: {}".format(status[1])) if status[1] is not None: - await asyncio.sleep(float(status[1])) + await asyncio.sleep(float(status[1])) # note, the timer on the last request won't matter that much since it's separate task and for the time of sleep it will give control to other tasks else: logger.debug("Sending message failed") break