From 5d16b8bd4a80b83998a2ad9371853dad149b4355 Mon Sep 17 00:00:00 2001 From: _run Date: Tue, 11 Oct 2022 19:13:10 +0400 Subject: [PATCH] Create continue_handling.py --- .../asynchronous_telebot/continue_handling.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/asynchronous_telebot/continue_handling.py diff --git a/examples/asynchronous_telebot/continue_handling.py b/examples/asynchronous_telebot/continue_handling.py new file mode 100644 index 0000000..4781cc4 --- /dev/null +++ b/examples/asynchronous_telebot/continue_handling.py @@ -0,0 +1,27 @@ +from telebot.async_telebot import AsyncTeleBot +from telebot.asyncio_handler_backends import ContinueHandling + + +bot = AsyncTeleBot('TOKEN') + +@bot.message_handler(commands=['start']) +async def start(message): + await bot.send_message(message.chat.id, 'Hello World!') + return ContinueHandling() + +@bot.message_handler(commands=['start']) +async def start2(message): + """ + This handler comes after the first one, but it will never be called. + But you can call it by returning ContinueHandling() in the first handler. + + If you return ContinueHandling() in the first handler, the next + registered handler with appropriate filters will be called. + """ + await bot.send_message(message.chat.id, 'Hello World2!') + +import asyncio +asyncio.run(bot.polling()) # just a reminder that infinity polling +# wraps polling into try/except block just as sync version, +# but you can use any of them because neither of them stops if you +# pass non_stop=True