J
J
jfresearch2022-04-21 14:06:11
API
jfresearch, 2022-04-21 14:06:11

How to register checking and waiting for the correct telebot input?

Tell me, please, how to register the correctness check and the expectation of the correct input

Source code:

def question3(message):
    question2 = message.text
    sql.execute(f"""UPDATE users SET answer2 = '{question2}' WHERE user_id = {message.chat.id}""")
...
    bot.register_next_step_handler(msg, question4)


The check should be that the first character is a tag: I tried both through the usual if else, and through while true As a result, either the error message is cycled and sent in a row, or break is triggered for the entire step and the following messages are not sent
question2[0] == '#'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coder_mihail, 2022-04-26
@coder_mihail

def question3(message):
    user_id = message.chat.id
    question3 = message.text
    if question3.startswith('#'):
        sql.execute("")
        msg = bot.send_message(user_id, 'Отлично! Следующий вопрос...')
        bot.register_next_step_handler(msg, question4)
    else:
        bot.send_message(user_id, 'Ошибка! Введите ещё раз!')
        bot.register_next_step_handler(msg, question3)

Don't use f-strings in SQL queries! Read about SQL injection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question