From 5112e5da36c592b9e125ffa13159aecc80949aca Mon Sep 17 00:00:00 2001 From: fr0stb1rd <199750943+b1rdfr0st@users.noreply.github.com> Date: Fri, 11 Jul 2025 16:01:24 +0300 Subject: [PATCH] Fix: Respect sleep_threshold=0 in invoke() to prevent unwanted FloodWait sleep This PR updates the `invoke()` method to correctly handle `sleep_threshold=0`. ### Before: Even when `sleep_threshold=0`, the client still waits for the full FloodWait duration. ### After: With this change: - If `sleep_threshold == 0`, it raises the FloodWait immediately (no sleep). - If `sleep_threshold < 0`, it always raises (never sleeps). - If `sleep_threshold > 0`, it only sleeps if `amount <= sleep_threshold`. This makes `sleep_threshold` behave more as expected and allows advanced bot handling logic outside of Pyrogram. Thanks! --- pyrogram/session/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 87d57409..ce02f458 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -421,7 +421,7 @@ class Session: except (FloodWait, FloodPremiumWait) as e: amount = e.value - if amount > sleep_threshold >= 0: + if sleep_threshold < 0 or amount > sleep_threshold: raise log.warning('[%s] Waiting for %s seconds before continuing (required by "%s")',