Does register_next_step_handler
support pass_bot
param?
#1878
-
Please answer these questions before submitting your issue. Thanks!
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 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
just add bot parameter to register_next_step hander like:
Something like this. The purpose is that you can pass keyword or positional arguments to your next function. |
Beta Was this translation helpful? Give feedback.
-
And use discussions next time please. |
Beta Was this translation helpful? Give feedback.
just add bot parameter to register_next_step hander like:
Something like this. The purpose is that you can pass keyword or positional arguments to your next function.