From e6017a2170982644aaa4ecf457a070bf98200cd6 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 9 Sep 2020 21:17:28 -0400 Subject: [PATCH] Handle cloudflare bans on webhook requests Fixes #5221 --- discord/webhook.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/discord/webhook.py b/discord/webhook.py index 1c097a088..7824c55ae 100644 --- a/discord/webhook.py +++ b/discord/webhook.py @@ -222,6 +222,10 @@ class AsyncWebhookAdapter(WebhookAdapter): # we are being rate limited if r.status == 429: + if not r.headers.get('Via'): + # Banned by Cloudflare more than likely. + raise HTTPException(r, data) + retry_after = response['retry_after'] / 1000.0 log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', _id, retry_after) await asyncio.sleep(retry_after) @@ -317,6 +321,10 @@ class RequestsWebhookAdapter(WebhookAdapter): # we are being rate limited if r.status == 429: if self.sleep: + if not r.headers.get('Via'): + # Banned by Cloudflare more than likely. + raise HTTPException(r, data) + retry_after = response['retry_after'] / 1000.0 log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', _id, retry_after) time.sleep(retry_after)