x3ron
@x3ron
Начинающий в Python'e, небольшой опыт в html

Что делать если при запуске программы выдает ошибку AttributeError: 'CallbackQuery' object has no attribute 'chat'?

Я запускаю программу:
import telebot
print('******1')
from config import token
print('****2')
from telebot import types
bot = telebot.TeleBot(token)


@bot.message_handler(commands = ['start'])
def welcome(message):
  bot.send_message(message.chat.id, 'Привет, {0.first_name}!\nЧтобы поискать статьи в техноблоге по моделям нажмите /tech'.format(message.from_user, bot.get_me()), parse_mode='html')
@bot.message_handler(commands = ['tech'])
def tech(gg):
  kb = types.InlineKeyboardMarkup()
  brand1 = types.InlineKeyboardButton(text='Kingsong', callback_data = 'kingsong')
  brand2 = types.InlineKeyboardButton(text='Inmotion', callback_data = 'inmotion')
  kb.add(brand1, brand2)
  bot.send_message(gg.chat.id, "Choose a brand", reply_markup=kb)
@bot.callback_query_handler(func = tech)
def tech_ob(callback):
  if call.data == 'kingsong':
    bot.send_message('KS')
  elif call.data == 'inmotion':
    bot.send_message('Im')

bot.polling(none_stop=True)

После того как я нажимаю на кнопку выводит ошибку(полный ее код):
Traceback (most recent call last):
File "main.py", line 26, in
bot.polling(none_stop=True)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 415, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 438, in __threaded_polling
polling_thread.raise_exceptions()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/util.py", line 81, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/six.py", line 703, in reraise
raise value
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/util.py", line 62, in run
task(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 282, in __retrieve_updates
self.process_new_updates(updates)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 337, in process_new_updates
self.process_new_callback_query(new_callback_querys)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 367, in process_new_callback_query
self._notify_command_handlers(self.callback_query_handlers, new_callback_querys)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 1907, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 1875, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 1896, in _test_filter
return test_cases.get(message_filter, lambda msg: False)(message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/telebot/__init__.py", line 1893, in
'func': lambda msg: filter_value(msg)
File "main.py", line 18, in tech
bot.send_message(gg.chat.id, "Choose a brand", reply_markup=kb)
AttributeError: 'CallbackQuery' object has no attribute 'chat'

Python версии 3.8.2, библиотека pyTelegramBotApi стоит нормально
  • Вопрос задан
  • 1621 просмотр
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
Это откуда такое?
@bot.callback_query_handler(func = tech)

@bot.callback_query_handler(func=lambda call: True)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы