D
D
Danya  2020-08-21 17:15:31
Python
Danya  , 2020-08-21 17:15:31

TelegramBOT not working?

Telegram BOT not working. After entering the phone number, the bot crashes, what's wrong?
Here is the code?

@bot.message_handler(commands=['start'])
def handle_text (message):
    bot.send_message(message.chat.id, "Введите ваше ФИО")
    @bot.message_handler(content_types=['text'])
    def user_n(message):
        db_name = message.text
        bot.register_next_step_handler(user_phone(message))

def user_phone(message):
    bot.send_message(message.chat.id, "Введите ваш Номер Телефона")
    @bot.message_handler(content_types=['text'])
    def user_na(message):
        db_phone = message.text
        bot.register_next_step_handler(user_email(message))

def user_email(message):
    bot.send_message(message.chat.id, "Введите ваш Эл.Почту")
    @bot.message_handler(content_types=['text'])
    def user_nam(message):
        db_email = message.text
        bot.register_next_step_handler(user_msg(message))

def user_msg(message):
    bot.send_message(message.chat.id, "Введите ваше сообщение")
    @bot.message_handler(content_types=['text'])
    def user_name(message):
        db_msg = message.text
        bot.register_next_step_handler(test(message))

def test(message):
    bot.send_message(message.chat.id, 'ФИО:', db_name, '\nТел:', db_phone, '\nПочта:', db_email, '\nСообщение', db_msg)


Console code:
2020-08-21 17:24:52,334 (util.py:68 WorkerThread2) ERROR - TeleBot: "TypeError occurred, args=("register_next_step_handler() missing 1 required positional argument: 'callback'",)
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "C:\Users\User\Desktop\My_Info_Bot\bot-db-2.py", line 25, in user_n
    bot.register_next_step_handler(user_phone(message))
TypeError: register_next_step_handler() missing 1 required positional argument: 'callback'
"
Traceback (most recent call last):
  File "C:\Users\User\Desktop\My_Info_Bot\bot-db-2.py", line 65, in <module>
    bot.polling(none_stop=True)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 427, in polling
    self.__threaded_polling(none_stop, interval, timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 451, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 111, in raise_exceptions
    six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\six.py", line 703, in reraise
    raise value
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "C:\Users\User\Desktop\My_Info_Bot\bot-db-2.py", line 25, in user_n
    bot.register_next_step_handler(user_phone(message))
TypeError: register_next_step_handler() missing 1 required positional argument: 'callback'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elvis, 2020-08-21
@Dr_Elvis

Read the error, you are clearly written:

TypeError: register_next_step_handler() missing 1 required positional argument: 'callback'

Read the documentation for the bot and find out that the register_next_step_handler function needs 2 arguments, and you pass 1. The stack trace says that 1 callback argument is missing. and read about callback, too, what it is in principle.

A
Alexander Karadiaur, 2021-09-09
@twiwter

I solved the problem by rewriting the code a bit. It was necessary to remove the lines @bot.message_handler(content_types=['text']). they are of no use here. Here is the actual code:

user_data= {
    'name': '',
    'phone': '',
    'email': '',
    'message': ''
}

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


def user_phone(message):
    user_data['name'] = message.text
    msg = bot.send_message(message.chat.id, 'Введите свой номер телефона')
    bot.register_next_step_handler(msg, user_email)

def user_email(message):
    user_data['phone'] = message.text
    msg = bot.send_message(message.chat.id, 'Введите Вашу эл. почту')
    bot.register_next_step_handler(msg, user_message)

def user_message(message):
    user_data['email'] = message.text
    msg = bot.send_message(message.chat.id, 'Введите ваше сообщение')
    bot.register_next_step_handler(msg, getresults)

def getresults(message):
    user_data['message'] = message.text
    bot.send_message(message.chat.id, f"ФИО: {user_data['name']} \nТел: {user_data['phone']} \nПочта: {user_data['email']} \nСообщение: {user_data['message']}")
    bot.clear_step_handler(message)

6139e3ace61ff086220998.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question