diff --git a/discord/gateway.py b/discord/gateway.py index b03544893..ed583495a 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -76,6 +76,12 @@ class GatewayRatelimiter: self.lock = asyncio.Lock() self.shard_id = None + def is_ratelimited(self): + current = time.time() + if current > self.window + self.per: + return False + return self.remaining == 0 + def get_delay(self): current = time.time() @@ -287,6 +293,9 @@ class DiscordWebSocket: def open(self): return not self.socket.closed + def is_ratelimited(self): + return self._rate_limiter.is_ratelimited() + @classmethod async def from_client(cls, client, *, initial=False, gateway=None, shard_id=None, session=None, sequence=None, resume=False): """Creates a main websocket for Discord from a :class:`Client`.