U
U
usjsksj2020-01-03 08:46:33
Bots
usjsksj, 2020-01-03 08:46:33

How to save user responses into variables for later use? Telegram? python?

To autocomplete files, you need to create a questionnaire like this:
Enter the full name
fio = user text
And so that I can then take his answer from her

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-01-03
@usjsksj

Use register_next_step_handler, passing the necessary variables to it

import telebot
from telebot import types


@bot.message_handler(commands=['start'])
def main(message):
    msg = bot.send_message(message.chat.id, 'Введите ФИО')
    bot.register_next_step_handler(msg, fio_step)

def fio_step(message):
    user_info = {}
    user_info['name'] = message.text
    msg = bot.send_message(message.chat.id, 'Введите возраст')
    bot.register_next_step_handler(msg, age_step, user_info)

def age_step(message, user_info):
    user_info['age'] = message.text
    print(user_info)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question