При создании бота в телеграмме для пересылки сообщения по ключевому слову
import telebot
bot = telebot.TeleBot('token')
my_id = int('1047621278')
@bot.message_handler(commands=['start'])
def start(message):
print(message)
@bot.message_handler(func=lambda message: 'ключевое слово' in message.text.lower(), content_types=['text'])
def repeat_all_messages(message):
bot.forward_message(my_id, message.chat.id, message.id)
bot.polling(none_stop=True)
ошибка:
Traceback (most recent call last):
File "C:\Users\sharafutdinovbd\PycharmProjects\bottelegramm\bot telega2.py", line 18, in <module>
bot.polling(none_stop=True)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 455, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 513, in __threaded_polling
raise e
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 478, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 88, in raise_exceptions
raise self.exception_info
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 296, in __retrieve_updates
self.process_new_updates(updates)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 357, in process_new_updates
self.process_new_messages(new_messages)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 383, in process_new_messages
self._notify_command_handlers(self.message_handlers, new_messages)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 2127, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 2093, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 2114, in _test_filter
return test_cases.get(message_filter, lambda msg: False)(message)
File "C:\Users\sharafutdinovbd\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 2111, in <lambda>
'func': lambda msg: filter_value(msg)
File "C:\Users\sharafutdinovbd\PycharmProjects\bottelegramm\bot telega2.py", line 13, in <lambda>
@bot.message_handler(func=lambda message: '@temamorg' in message.text.lower())
AttributeError: 'NoneType' object has no attribute 'lower'
Process finished with exit code 1
Ответы (1 шт):
Автор решения: Alex Zab
→ Ссылка
Ошибка 'NoneType' object has no attribute 'lower' значит что ваш message.text.lower() ничего не возвращает, как можно что то делать с пустотой?) ¯\_( ͡° ͜ʖ ͡°)_/¯¯\_(ツ)_/¯
Правильное построение бота -
import telebot
bot = telebot.TeleBot('token')
my_id = 1047621278
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, "Привeт")
@bot.message_handler(content_types=['text'])
def repeat_all_messages(message):
if 'ключевое слово' in message.text.lower():
bot.forward_message(my_id, message.chat.id, message.id)
bot.polling(none_stop=True)