diff --git a/discord/client.py b/discord/client.py index fae80832b9..8c85ea8441 100644 --- a/discord/client.py +++ b/discord/client.py @@ -213,9 +213,9 @@ class Client: Defaults to `1` second. .. versionadded:: 2.5 - maximum_rate_limit_time: :class:`int` - The maximum amount of seconds the client is allowed to wait on a rate limit, - or otherwise error out. Defaults to `-1`, or infinite. + rate_limit_timeout: :class:`float` + The maximum amount of seconds the client is allowed to wait on a rate limit + before raising an exception. Defaults to `-1`, or infinite. .. versionadded:: 2.5 @@ -251,6 +251,7 @@ def __init__( bucket_storage = options.pop("bucket_storage_cls", BucketStorage)( options.pop("per", 1), options.pop("concurrency", 50) ) + rate_limit_timeout: float = options.pop("rate_limit_timeout", -1) self.http: HTTPClient = HTTPClient( bucket_storage, @@ -259,7 +260,7 @@ def __init__( proxy_auth=proxy_auth, unsync_clock=unsync_clock, loop=self.loop, - maximum_rate_limit_time=options.pop("maximum_rate_limit_time", -1), + rate_limit_timeout=rate_limit_timeout, ) self._handlers: dict[str, Callable] = {"ready": self._handle_ready} diff --git a/discord/http.py b/discord/http.py index 2ef827523f..c2f53a53df 100644 --- a/discord/http.py +++ b/discord/http.py @@ -144,7 +144,7 @@ def __init__( proxy_auth: aiohttp.BasicAuth | None = None, loop: asyncio.AbstractEventLoop | None = None, unsync_clock: bool = True, - maximum_rate_limit_time: int | float = -1, + rate_limit_timeout: float = -1, ) -> None: self.loop: asyncio.AbstractEventLoop = ( asyncio.get_event_loop() if loop is None else loop @@ -156,7 +156,7 @@ def __init__( self.proxy: str | None = proxy self.proxy_auth: aiohttp.BasicAuth | None = proxy_auth self.use_clock: bool = not unsync_clock - self.maximum_rate_limit_time = maximum_rate_limit_time + self.rate_limit_timeout = rate_limit_timeout user_agent = ( "DiscordBot (https://pycord.dev, {0}) Python/{1[0]}.{1[1]} aiohttp/{2}" @@ -313,12 +313,12 @@ async def request( is_global: bool = data.get("global", False) if ( - retry_after > self.maximum_rate_limit_time - and self.maximum_rate_limit_time != -1 + retry_after > self.rate_limit_timeout + and self.rate_limit_timeout != -1 ): raise HTTPException( response, - f"Retrying rate limit would take longer than the maximum of {self.maximum_rate_limit_wait_time} seconds given", + f"Retrying rate limit would take longer than the maximum of {self.rate_limit_timeout} seconds given", ) if is_global: @@ -346,7 +346,7 @@ async def request( continue # we've received a 500, 502, or 504, unconditional retry - if response.status in {500, 502, 504}: + if response.status in (500, 502, 504): await asyncio.sleep(1 + tries * 2) continue