Answer the question
In order to leave comments, you need to log in
How to fix 'NoneType' object has no attribute 'chat' error?
@bot.message_handler(content_types=["text"])
def handle_text(message):
keyboardmain = types.InlineKeyboardMarkup(row_width=2)
first_button = types.InlineKeyboardButton(text="Youtube", callback_data="first")
second_button = types.InlineKeyboardButton(text="Twitter", callback_data="second")
keyboardmain.add(first_button, second_button)
bot.send_message(message.chat.id, "Select ", reply_markup=keyboardmain)
@bot.callback_query_handler(func=lambda call: True)
def handle_text(call, message=None):
if call.data == "first":
keyboard = types.InlineKeyboardMarkup()
rele1 = types.InlineKeyboardButton(text="Оставьте отзыв", callback_data="3")
backbutton = types.InlineKeyboardButton(text="back", callback_data="a")
keyboard.add(rele1, backbutton)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
text="Текст",
reply_markup=keyboard)
msg = "Пользователь {} написал \"{}\".".format(message.chat.id, message.messag_id)
bot.send_message('-100000000000', msg)
File "C:/Users/99455/PycharmProjects/untitled3/main.py", line 67, in handle_text
msg = "Пользователь {} написал \"{}\".".format(message.chat.id, message.messag_id)
AttributeError: 'NoneType' object has no attribute 'chat'
Answer the question
In order to leave comments, you need to log in
the message object must have a chat attribute, but the object is empty. The problem is either in the previous code, or you need to check and fill in some default values.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question