11diff --git a/src/_discord/http.py b/src/_discord/http.py
2- index 79455a0..4c16c2b 100644
2+ index 9eb7837..9ad7137 100644
33--- a/src/_discord/http.py
44+++ b/src/_discord/http.py
55@@ -25,6 +25,8 @@ DEALINGS IN THE SOFTWARE.
@@ -11,7 +11,7 @@ index 79455a0..4c16c2b 100644
1111 import asyncio
1212 import logging
1313 import sys
14- @@ -100 ,6 +102 ,22 @@ async def json_or_text(response: aiohttp.ClientResponse) -> dict[str, Any] | str
14+ @@ -101 ,6 +103 ,22 @@ async def json_or_text(response: aiohttp.ClientResponse) -> dict[str, Any] | str
1515 return text
1616
1717
@@ -34,7 +34,7 @@ index 79455a0..4c16c2b 100644
3434 class Route:
3535 def __init__(self, method: str, path: str, **parameters: Any) -> None:
3636 self.path: str = path
37- @@ -166 ,7 +184 ,7 @@ class HTTPClient:
37+ @@ -167 ,7 +185 ,7 @@ class HTTPClient:
3838 proxy: str | None = None,
3939 proxy_auth: aiohttp.BasicAuth | None = None,
4040 loop: asyncio.AbstractEventLoop | None = None,
@@ -43,7 +43,7 @@ index 79455a0..4c16c2b 100644
4343 ) -> None:
4444 self.loop: asyncio.AbstractEventLoop = (
4545 asyncio.get_event_loop() if loop is None else loop
46- @@ -177 ,7 +195 ,7 @@ class HTTPClient:
46+ @@ -178 ,7 +196 ,7 @@ class HTTPClient:
4747 self._global_over: asyncio.Event = asyncio.Event()
4848 self._global_over.set()
4949 self.token: str | None = None
@@ -52,15 +52,15 @@ index 79455a0..4c16c2b 100644
5252 self.proxy: str | None = proxy
5353 self.proxy_auth: aiohttp.BasicAuth | None = proxy_auth
5454 self.use_clock: bool = not unsync_clock
55- @@ -188 ,6 +206 ,7 @@ class HTTPClient:
55+ @@ -189 ,6 +207 ,7 @@ class HTTPClient:
5656 self.user_agent: str = user_agent.format(
5757 __version__, sys.version_info, aiohttp.__version__
5858 )
5959+ self.user_limit = UserLimit(self.loop)
6060
6161 def recreate(self) -> None:
6262 if self.__session.closed:
63- @@ -234 ,8 +253 ,23 @@ class HTTPClient:
63+ @@ -235 ,8 +254 ,23 @@ class HTTPClient:
6464 "User-Agent": self.user_agent,
6565 }
6666
@@ -85,7 +85,7 @@ index 79455a0..4c16c2b 100644
8585 # some checking if it's a JSON request
8686 if "json" in kwargs:
8787 headers["Content-Type"] = "application/json"
88- @@ -279 ,6 +313 ,11 @@ class HTTPClient:
88+ @@ -280 ,6 +314 ,11 @@ class HTTPClient:
8989 kwargs["data"] = form_data
9090
9191 try:
@@ -97,16 +97,25 @@ index 79455a0..4c16c2b 100644
9797 async with self.__session.request(
9898 method, url, **kwargs
9999 ) as response:
100- @@ -316 ,7 +355,7 @@ class HTTPClient:
100+ @@ -319 ,7 +358,8 @@ class HTTPClient:
101101
102102 # we are being rate limited
103103 if response.status == 429:
104104- if not response.headers.get("Via") or isinstance(data, str):
105- + if not response.headers.get("Via") or isinstance(data, str) or ("code" in data and data["code"] == 20016):
105+ + retry_after: float = data.get("retry_after", 0)
106+ + if not response.headers.get("Via") or isinstance(data, str) or ("code" in data and data["code"] == 20016) or retry_after > 30:
106107 # Banned by Cloudflare more than likely.
107108 raise HTTPException(response, data)
108109
109- @@ -401,22 +440,28 @@ class HTTPClient:
110+ @@ -329,7 +369,6 @@ class HTTPClient:
111+ )
112+
113+ # sleep a bit
114+ - retry_after: float = data["retry_after"]
115+ _log.warning(fmt, retry_after, bucket)
116+
117+ # check if it's a global rate limit
118+ @@ -406,22 +445,28 @@ class HTTPClient:
110119
111120 # login management
112121
0 commit comments