Answer the question
In order to leave comments, you need to log in
How to record the data that is sent to the bot?
The bot is given the usual str, they must be written to a regular list (data), but the list is empty as a result and nothing was written, what to do?
import telebot
bot = telebot.TeleBot(' - - - ')
data = []
def main():
@bot.message_handler(commands = ['start'])
def foo(message):
msg = bot.send_message(message.chat.id,'введите имя')
bot.register_next_step_handler(msg,name)
def name(message):
name = message.text
data.append(name)
msg = bot.send_message(message.chat.id,'введите возраст')
bot.register_next_step_handler(msg,age)
def age(message):
data.append(message.age)
return data
if __name__ == '__main__':
print(main())
bot.enable_save_next_step_handlers(delay=2)
bot.load_next_step_handlers()
bot.polling()
Answer the question
In order to leave comments, you need to log in
The list is filled, it's just that in the current code it is returned only once (at the very beginning, when it is still empty). main() only runs once.
Can be seen by adding the /info command for example
@bot.message_handler(commands = ['info'])
def send_info(message):
bot.send_message(message.chat.id, f'data={data}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question