add_handler()¶
- Client.add_handler()¶
Register an update handler.
Usable by Users BotsYou can register multiple handlers, but at most one handler within a group will be used for a single update. To handle the same update more than once, register your handler using a different group id (lower group id == higher priority). This mechanism is explained in greater details at More on Updates.
ConnectHandler,DisconnectHandler,StartHandlerandStopHandlerare lifecycle callbacks rather than update handlers: they never reach a group, group is ignored, and the client holds one of each, so registering a second one replaces the first.- Parameters:
handler (
Handler) – The handler to be registered.group (
int, optional) – The group identifier, defaults to 0.
- Returns:
tuple– A tuple consisting of (handler, group).
Example
from wzgram import Client from wzgram.handlers import MessageHandler async def hello(client, message): print(message) app = Client("my_account") app.add_handler(MessageHandler(hello)) app.run()