M
M
Misha Utka2021-06-07 11:43:01
Python
Misha Utka, 2021-06-07 11:43:01

Why is bot.register_next_step_handler not working?

The code should send a message

Enter *percentage* you want to set
and wait for the percentage itself, but he does not survive anything and instead of the percentage sets just the same message that he himself sent
Enter *percentage* you want to set
How to solve it?
def izmproc(call, user_type, user_id):
      global a1
      a1 = user_id
      mess = database.с_message(user_id)
      code = database.c_code(user_id)
      chat_id = call.message.chat.id
      code2 = str(chat_id)[:5]
      with sqlite3.connect("evidence.db") as con:
        cur = con.cursor()
        result = cur.execute('SELECT * FROM `c` WHERE `id` = ?', (user_id,)).fetchall()
        for row in result:
          username2 = repl(row[3])
      try:
        if (code2 == code) or (call.message.chat.id == support) or (call.message.chat.id == admin):

          message = bot.send_message(chat_id, f" Введите *процент* который хотите установить [{row[4]}](https://t.me/{row[3]})", parse_mode="Markdown", disable_web_page_preview=True)
          bot.register_next_step_handler(message, proc_c(call, a1))
      except Exception as e:
        print(e)

def proc_c(call, argument):
  user_id = argument
  mess = database.c_message(user_id)
  code = database.c_code(user_id)
  chat_id = call.message.chat.id
  code2 = str(chat_id)[:5]
  try:
    if (code2 == code) or (call.message.chat.id == support) or (call.message.chat.id == admin):
      result = database.user_update_f(user_id, call.message.text)
      if (result == 1):
        bot.send_message(call.message.chat.id, f' Процент  *изменен*\nНовый процент: {database.user_f(user_id)}', parse_mode="Markdown")
      if (result == 2):
        bot.send_message(call.message.chat.id, f' *Ошибка*', parse_mode="Markdown")
    else:
      bot.send_message(call.message.chat.id, f' *Ошибка*', parse_mode="Markdown")
  except Exception as e:
    print(e)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-06-07
@ut1ka

bot.register_next_step_handler(message, proc_c(call, a1))

when you call register_next_step_handler , you also call the proc_c function , and you need not to call it, but pass it as a parameter.
The parameters with which the passed function should be called must come as separate parameters after the same function
bot.register_next_step_handler(message, proc_c, call, a1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question