C
C
Cockie2021-01-12 18:12:02
Python
Cockie, 2021-01-12 18:12:02

How can I make the telegram bot constantly ask and record the user's response?

It is necessary that after the user enters the command, the bot asks a question and accepts an answer from the user, and so on endlessly until the user writes, for example, cancel, he only thought of this, but of course this does not work:

import telebot

bot = telebot.TeleBot('')


@bot.message_handler(content_types=['text'])
def send_text(m):
  if m.text.lower() == 'время':
    global otvet
    otvet = []
    while True:
      bot.send_message(m.chat.id, 'давай')
      bot.register_next_step_handler(m,ggh)
      def ggh(m):
        g = str(m.text)
        otvet.append(g)
        
bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-12
@Cockie

Of course, you are not using the next step handler
correctly There is a good use case on github
https://github.com/eternnoir/pyTelegramBotAPI/blob...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question