V
V
Volodya2021-10-18 19:20:29
Python
Volodya, 2021-10-18 19:20:29

How to fix AttributeError: 'Message' object has no attribute 'data' telebot Python error?

@bot.callback_query_handler(func=lambda call:True)
def shop(call):
    if call.data == 'car_salon':
        inline = types.InlineKeyboardMarkup()
        markup_inl1 = types.InlineKeyboardButton('Toyota', callback_data='toyota121')
        markup_inl2 = types.InlineKeyboardButton('Audi', callback_data='audi121')
        markup_inl3 = types.InlineKeyboardButton('Bmw', callback_data='bmw121')
        markup_inl4 = types.InlineKeyboardButton('Mersedes', callback_data='mersedes121')
        inline.add(markup_inl1, markup_inl2, markup_inl3,markup_inl4)


        bot.send_message(call.message.chat.id, 'Виберіть марку авто:', reply_markup=inline)
    if call.data == 'bmw121':
        bot.send_message(call.message.chat.id, 'Доступні машини:')
        for id_user in sql.execute(f"SELECT id FROM users WHERE login = '{user_login}'"):
            pass
        bot.send_photo(id_user, codecs.open(r"C:\Users\HOME\PycharmProjects\Кеша бот python\Новий бот-Ігра\Фото\Car\bmw_E39.jpg", 'rb'), caption='Bmw e39 - 150.000грн')
        bot.send_photo(id_user, codecs.open(r"C:\Users\HOME\PycharmProjects\Кеша бот python\Новий бот-Ігра\Фото\Car\bmw_x3_2011.jpg ", 'rb'), caption='Bmw X3 - 520.000грн')
        bot.send_photo(id_user, codecs.open(r"C:\Users\HOME\PycharmProjects\Кеша бот python\Новий бот-Ігра\Фото\Car\bmw_m5f90.jpg", 'rb'), caption='Bmw 5mF90 - 3.000.000грн')
        bot.send_message(call.message.chat.id, 'Виберіть авто!' )

This is not the whole code, but I think the error is here. I
wrote a bot and the error will appear:

Traceback (most recent call last):
  File "C:/Users/HOME/PycharmProjects/Кеша бот python/Новий бот-Ігра/main.py", line 270, in <module>
    bot.polling(none_stop=True, interval=0)
  File "C:\Users\HOME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 623, in polling
    self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
  File "C:\Users\HOME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 682, in __threaded_polling
    raise e
  File "C:\Users\HOME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 645, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\HOME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 130, in raise_exceptions
    raise self.exception_info
  File "C:\Users\HOME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 82, in run
    task(*args, **kwargs)
  File "C:/Users/HOME/PycharmProjects/Кеша бот python/Новий бот-Ігра/main.py", line 82, in shop
    if call.data == 'car_salon':
AttributeError: 'Message' object has no attribute 'data'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-10-18
Burnout @vova1244

For inline buttons you don't need to do register_next_step_handler. Handling clicks through decoratorscallback_query_handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question