It is necessary to implement the code so that it works like this: the bot asks a question -the user answers YES, NO. If the user answers YES, then there are no more questions, but if NO, then the question is asked again YES, NO. It reacts to the first YES /NO, but not to the second -the first block reacts to commands all the time, yes or no. How can this issue be resolved? I thought that maybe if you pass the value false to the lambda function, then the handler will stop and the code will go further, but no -it completely stops processing any messages, except no, yes. PyTelegramBotAPI Library Here is a variation of such a line. @ bot.message_handler (func= lambda message: message if message.text.upper ()== 'YES' or message.text.upper ()== 'NO' else False) The problem is def 3_step
@bot.message_handler(func= lambda c: True, commands=['komanda'])
def 1_step(message):
'тут код продолжается'
for i in values:
spisok.append(i)
'тут код продолжается'
bot.register_next_step_handler(msg, 2_step)
def 2_step(message):
'тут код продолжается'
bot.register_next_step_handler(msg, 3_step)
def 3_step(message):
@bot.message_handler(func=lambda message: message.text== 'YES' or 'NO')
def yes_no(message):
if message.text== 'YES':
'выполняется блок'
elif message.text== 'NO':
@bot.message_handler(func=lambda message: message.text== 'YES' or 'NO') #<-не работает
def yes_no_2(message):
if message.text== 'YES':
'выполняется код'
elif message.text== 'NO':
'выполняется код'
else:
bot.send_message(id, 'Пиши yes или no')
else:
bot.send_message(id, 'Пиши yes или no')
bot.register_next_step_handler(msg, 4_step)
- python : Differences between a regular Telegram bot and an asynchronous one?
- python : Sending PIL.Image image as document via pyTelegramBotApi
- How to make the bot respond to commands in the telegram channel. Python, Telebot
- python : TypeError: object of type 'function' has no len()
- python : Getting data from invoice payment PyTelegramBotAPI
- How to randomly open photos in Telegram Bot in Python?
- python : How to embed an image in a message with text for telegram
- number of keyboard buttons per line in keyboard under telebot python telegram message
- python : AttributeError("'CallbackQuery' object has no attribute 'call'")
- python : make sure that the buttons are not detected
@ bot.message_handler (commands= ['yes_no_2']) try this
Master's Time2021-12-29 19:30:13