Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carl bot v2.0 #7

Merged
merged 2 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ async def request(
remaining = response.headers.get("X-Ratelimit-Remaining")
if remaining == "0" and response.status != 429:
# we've depleted our current bucket
if response.status != 200 or response.status != 204:
print(f"RatelimitReached: status: {response.status}, url: {url}, method: {method}")
delta = utils._parse_ratelimit_header(
response, use_clock=self.use_clock
)
Expand All @@ -319,6 +321,7 @@ async def request(

# we are being rate limited
if response.status == 429:
print(f"APIRatelimitError: status: {response.status}, url: {url}, method: {method}")
if not response.headers.get("Via") or isinstance(data, str):
# Banned by Cloudflare more than likely.
raise HTTPException(response, data)
Expand All @@ -335,6 +338,7 @@ async def request(
# check if it's a global rate limit
is_global = data.get("global", False)
if is_global:
print(f"GlobalRateLimitReached: status: {response.status}, url: {url}, method: {method}")
_log.warning(
(
"Global rate limit has been hit. Retrying in"
Expand All @@ -361,6 +365,7 @@ async def request(
continue

# the usual error cases
print(f"APIError: status: {response.status}, url: {url}, method: {method}")
if response.status == 403:
raise Forbidden(response, data)
elif response.status == 404:
Expand Down
Loading