Please answer these questions before submitting your issue. Thanks!
- What version of pyTelegramBotAPI are you using?
4.9.0
- What OS are you using?
Windows
- What version of python are you using?
3.11
entry.py
def register_handlers(tg_bot: telebot.TeleBot) -> None:
tg_bot.register_message_handler(callback=command_start, pass_bot=True, commands=["start", "help"])
tg_bot.register_message_handler(callback=admin_panel, pass_bot=True, commands=["admin"])
tg_bot.register_callback_query_handler(
callback=bind_admin, func=lambda callback: callback.data == "bind_admin", pass_bot=True
)
handler.py
def admin_panel(message: telebot.types.Message, bot: telebot.TeleBot) -> None:
"""
:param message:
:param bot:
:return:
"""
markup = telebot.util.quick_markup(
{
"Bind admin": {"callback_data": "bind_admin"},
}
)
bot.send_message(chat_id=message.chat.id, text="Admin panel here.", reply_markup=markup)
def bind_admin(callback: telebot.types.CallbackQuery, bot: telebot.TeleBot) -> None:
"""
:param callback:
:param bot:
:return:
"""
bot.send_message(chat_id=callback.message.chat.id, text="Please type your admin email.")
bot.register_next_step_handler(message=callback.message, callback=bind_admin_email, pass_bot=True)
def bind_admin_email(message: telebot.types.Message, bot: telebot.TeleBot) -> None:
"""
:param message:
:param bot:
:return:
"""
email = message.text
logger.debug(email)
user_obj = models.User.objects.filter(email=email).first()
if not user_obj:
bot.send_message(chat_id=message.chat.id, text="User not found.")
Since handlers and bot instance are in different file, using decorators will cause import error. I use register_message_handler with pass_bot=True, but register_next_step_handler seems no pass_bot param.
Please answer these questions before submitting your issue. Thanks!
4.9.0
Windows
3.11
entry.py
handler.py
Since handlers and bot instance are in different file, using decorators will cause import error. I use register_message_handler with pass_bot=True, but register_next_step_handler seems no
pass_botparam.