From e25ea6f3c177eb5e265fe70d459253fac52bb7c6 Mon Sep 17 00:00:00 2001 From: Quintenvw Date: Tue, 29 Oct 2024 10:48:06 +0100 Subject: [PATCH] fix: handle improper 1000 closures by discord (#2632) * Handle improper 1000 closures by Discord Signed-off-by: Quintenvw * style(pre-commit): auto fixes from pre-commit.com hooks --------- Signed-off-by: Quintenvw Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- discord/gateway.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/discord/gateway.py b/discord/gateway.py index 7a765405af..47d4853a65 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -587,7 +587,16 @@ def latency(self) -> float: def _can_handle_close(self): code = self._close_code or self.socket.close_code - return code not in (1000, 4004, 4010, 4011, 4012, 4013, 4014) + is_improper_close = self._close_code is None and self.socket.close_code == 1000 + return is_improper_close or code not in ( + 1000, + 4004, + 4010, + 4011, + 4012, + 4013, + 4014, + ) async def poll_event(self): """Polls for a DISPATCH event and handles the general gateway loop.