From a5cd3b92a6889ba8575c7831719073ba8f049670 Mon Sep 17 00:00:00 2001 From: Ling-ex Date: Fri, 16 May 2025 08:47:47 +0000 Subject: [PATCH] Feat: Add group Parameter to the Decorator.on_error. Signed-off-by: Ling-ex --- pyrogram/methods/decorators/on_error.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pyrogram/methods/decorators/on_error.py b/pyrogram/methods/decorators/on_error.py index 7c3294d1..dc192b1e 100644 --- a/pyrogram/methods/decorators/on_error.py +++ b/pyrogram/methods/decorators/on_error.py @@ -24,7 +24,11 @@ from pyrogram.filters import Filter class OnError: - def on_error(self=None, errors=None) -> Callable: + def on_error( + self=None, + errors=None, + group: int = 0, + ) -> Callable: """Decorator for handling new errors. This does the same thing as :meth:`~pyrogram.Client.add_handler` using the @@ -34,16 +38,19 @@ class OnError: errors (:obj:`~Exception`, *optional*): Pass one or more errors to allow only a subset of errors to be passed in your function. + + group (``int``, *optional*): + The group identifier, defaults to 0. """ def decorator(func: Callable) -> Callable: if isinstance(self, pyrogram.Client): - self.add_handler(pyrogram.handlers.ErrorHandler(func, errors), 0) + self.add_handler(pyrogram.handlers.ErrorHandler(func, errors), group) elif isinstance(self, Filter) or self is None: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append((pyrogram.handlers.ErrorHandler(func, self), 0)) + func.handlers.append((pyrogram.handlers.ErrorHandler(func, self), group)) return func