@kir1g
Начинающий программист

Не запускается бот, дает кучу ошибок. что делать?

import telebot
from telebot import types

bot = telebot.TeleBot('токен')

@bot.message_handler(commands='start', func = lambda m: True)
def welcome(message):
    buttons = types.ReplyKeyboardMarkup(resize_keyboard=True)
    but_reg = types.KeyboardButton('/reg')
    but_hm = types.KeyboardButton('/help')
    buttons.add(but_reg, but_hm)
    bot.send_message(message.chat.id, 'Привет', reply_markup=buttons)

@bot.message_handler(func = lambda m: True)
def reg_reg(message):
    if message.text == '/reg':
        bot.send_message(message.from_user.id, "Для того что бы зарегистрироваться. Напишите мне ваше имя и фамилию")
        bot.register_next_step_handler(message, name_reg)

def name_reg(message):
    global name
    name = message.text
    bot.send_message(message.from_user.id, "Теперь напишите как мне к вам обращаться")
    bot.register_next_step_handler(message, login_reg)

def login_reg(message):
    global login
    login = message.text
    bot.send_message(message.from_user.id, "И наконец напишите мне ваш возраст")
    bot.register_next_step_handler(message, age_reg)

def age_reg(message):
    global age
    while age == 0:
        try:
            age = int(message.text)
        except Exception:
            bot.send_message(message.from_user.id, "Для того что бы я вас понял нужно ввести целое, натуральное число.")
bot.polling()


Traceback (most recent call last):
File "C:\Users\kirzh\PycharmProjects\pythonProject\bot.py", line 41, in
bot.polling()
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 514, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 573, in __threaded_polling
raise e
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 535, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\util.py", line 87, in raise_exceptions
raise self.exception_info
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 325, in __retrieve_updates
self.process_new_updates(updates)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 394, in process_new_updates
self.process_new_messages(new_messages)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 420, in process_new_messages
self._notify_command_handlers(self.message_handlers, new_messages)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 2235, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 2201, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 2222, in _test_filter
return test_cases.get(message_filter, lambda msg: False)(message)
File "C:\Users\kirzh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telebot\__init__.py", line 2218, in
'commands': lambda msg: msg.content_type == 'text' and util.extract_command(msg.text) in filter_value,
TypeError: 'in ' requires string as left operand, not NoneType
  • Вопрос задан
  • 65 просмотров
Решения вопроса 1
@twistfire92
Python backend developer
В первом хэндлере оставьте только
@bot.message_handler(commands=['start'])
Уберите func = lambda m: True
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@MEDIOFF
Python Developer
@bot.message_handler(commands=['start'], func = lambda m: True)

Команды передайте списком
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы