Please tell me how to exit any step when using this method, so that at each of them, for example, you can press a button, and the cycle ends.
Sample code:
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def process_start(message):
board = types.InlineKeyboardMarkup()
cancel = types.InlineKeyboardButton(text="Отмена", callback_data="Отмена")
board.add(cancel)
text = 'start'
msg = bot.send_message(message.chat.id, text, reply_markup=cancel)
bot.register_next_step_handler(mgs, process_mid)
def process_mid(message):
board = types.InlineKeyboardMarkup()
cancel = types.InlineKeyboardButton(text="Отмена", callback_data="Отмена")
board.add(cancel)
text = 'mid'
msg = bot.send_message(message.chat.id, text, reply_markup=cancel)
bot.register_next_step_handler(msg, process_end)
def process_end(message):
text = 'end'
bot.send_message(message.chat.id, text)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == "Отмена":
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Отменено.')
bot.polling(none_stop=True)
When you click on CANCEL, everything works, the button disappears and is replaced with text, but the cycle itself does not end.
Share
Anthony , check pyTelegramBotAPI version – tested on 3.6.6
David Estrada is probably the dumbest question on the Toaster, how to check the version? Since I installed and forgot / scored and did not update …
David Estrada ,
pip list
pyTelegramBotAPI (3.5.1)
Anthony ,
pip install pyTelegramBotAPI -U
Better not to update unnecessarily, because in the update, changes may arrive that affect the functionality and the script will stop working.
David Estrada , so I thought so, I don't know how to solve this issue yet …
David Estrada , I managed to do this:
But there is a big BUT, after cancellation, the next message / command to the bot is ignored, does not accept it, the second is already accepted normally.
I thought that the button from the keyboard is “inline” in the bot, after the end, and then there is a problem with the loop