S
S
Spoon in the brain2019-05-29 22:27:09
Python
Spoon in the brain, 2019-05-29 22:27:09

Saving user input to a list (pyTelegramBotAPI)?

Good evening! Now I will throw the code in the forehead:

username = []


@bot.message_handler(commands=['start'])
def any_msg(message):
  menu_btns=telebot.types.ReplyKeyboardMarkup(True,True)
  menu_btns.row('Пройти регистрацию')
  bot.send_message(message.chat.id,'Здравствуйте! Меня зовут ***. Для работы со мной советую пройти регистрацию!', reply_markup=menu_btns)

@bot.message_handler(content_types = ['text'])
def msg(message):
        if message.text == 'Пройти регистрацию':
          bot.send_message(message.chat.id, 'Хорошо, начнём с простого как мне вас звать?')

#Тут скорее всего полный бред...
@bot.message_handler(func = lambda message: True, content_types = ['text'])
def username(message):
  global username
  username.append(message.text)
  bot.reply_to(message, 'Okey, ' + username + '!')

Now I will ask a few questions, how to store user information in the list, or how to read it at all?
Should MongoDB be used for user information?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil K., 2019-06-06
@vessels

@bot.message_handler(commands=['uiscreate'])
def uis_request_domain(message):
    if message.text.lower() == 'отмена':
        bot.send_message(message.from_user.id, 'Выполнение команды отменено')
        return
    send = bot.send_message(message.chat.id, 'Создание пользователя\nВведите почтовый домен:\n'
                                             'domain.ru')
    bot.register_next_step_handler(send, uis_request_data)


def uis_request_data(message):
    global domain_uis
    domain_uis = message.text.lower()
    if message.text.lower() == 'отмена':
        bot.send_message(message.from_user.id, 'Выполнение команды отменено')
        return
    send = bot.send_message(message.chat.id, 'Введите: ФИО должность телефон')
    bot.register_next_step_handler(send, create_uis)


def create_uis(message):
    last = message.text.split()[0]
    first = message.text.split()[1]
    middle = message.text.split()[2]
    position = message.text.split()[3]
    phone = message.text.split()[4]
  
  <...>

I
Irina, 2019-05-30
@vera_ira

The getUpdates method is used to get information.
If you need to save information about all requests and all users, you will need databases https://python-scripts.com/database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question