R
R
Roman Shavukhin2020-06-14 16:03:10
Python
Roman Shavukhin, 2020-06-14 16:03:10

What should I do if I get the error AttributeError: 'CallbackQuery' object has no attribute 'chat' when starting the program?

I run the program:

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)

After I click on the button, I get an error (its full code):
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 version 3.8.2, pyTelegramBotApi library is fine

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-14
@x3ron

Where is this from?
@bot.callback_query_handler(func = tech)

@bot.callback_query_handler(func=lambda call: True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question