0

Пишу бота, и не знаю как реализовать регистрацию не при помощи пошагового бота, пользователь вводит Имя, Фамилию, Должность, которые сохраняются в БД.

1 ответ 1

2
@bot.message_handler(commands=['start'])
def start(message):
    msg = bot.send_message(message.chat.id, 'Введите Имя, Фамилию, Должность', parse_mode='Markdown')
    bot.register_next_step_handler(msg, start_2)


def start_2(message):
    first = message.text.split()[0]
    last = message.text.split()[1]
    position = message.text.split()[2]

    # print(first, last, position)
    create_user_db(message.chat.id, first, last, position)


def create_user_db(id_tlgrm, first, last, position):
    conn = sqlite3.connect(db)
    cursor = conn.cursor()
    db_data = [(id_tlgrm, first, last, position)]
    cursor.executemany('INSERT INTO users VALUES (?, ?, ?, ?)', db_data)
    conn.commit()
2
  • Спасибо огромное! 16 мая 2021 в 11:07
  • Если ответ является решением вопроса, пожалуйста отметьте его таковым. Это поможет другим пользователям.
    – Violet
    16 мая 2021 в 11:08

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.