Answer the question
In order to leave comments, you need to log in
@bot.callback_query_handler doesn't work. What is the problem ???
import telebot
from telebot import types
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
bot = telebot.TeleBot('my token');
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Hello {0.first_name}! I'm a bot from Citylink.'.format(message.from_user , bot.get_me()),
parse_mode='html')
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Acs")
item2 = types.KeyboardButton("Video Surveillance")
item3 = types.KeyboardButton( "SCS")
item4 = types.KeyboardButton("Security - Fire Alarm"
bot.send_message(message.chat.id, 'Select service:', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def usl(message):
if message.text == 'ACS':
bot .send_message(message.chat.id, 'The request has been sent. The executor will contact you soon.')
elif message.text == 'Video surveillance':
markup = types.InlineKeyboardMarkup()
markup.row_width = 2
i1 = types.InlineKeyboardButton(' Apartment', callback_data='kv')
i2 = types.InlineKeyboardButton('Office', callback_data='of')
markup.add(i1, i2)
bot.send_message(message.chat.id, 'Select video surveillance delivery location',reply_markup=markup)
def dalv(message):
bot.send_message(message.chat.id, 'Выбирите тип камеры:')
markup = types.InlineKeyboardMarkup()
markup.row_width = 3
ii1 = types.InlineKeyboardButton('IP', callback_data='ip')
ii2 = types.InlineKeyboardButton('Аналог', callback_data='an')
@bot.callback_query_handler(lambda usl: usl.data=="kv")
def callback_query(call):
if usl.data == "kv":
bot.answer_callback_query('Квартира. Ответ записан')
dalv()
elif usl.data == "of":
bot.answer_callback_query('Офис. Ответ записан.')
dalv()
@bot.callback_query_handler(func=lambda call: True)
def calltip(call):
if call.data == 'IP':
bot.callback_query_handler('IP camera. Response recorded.')
bot.callback_query_handler('Callback sent. The executor will contact you shortly.')
elif call.data == 'Analog':
bot.send_message( 'Analog camera. Response recorded.')
bot.send_message('Submission sent. The executor will contact you shortly.')
bot.polling(none_stop=True)
I'm making a python bot. I'm new to this so please explain in detail. Can you suggest what is wrong?
Traceback (most recent call last):
File "E:\code\cityBot\bot.py", line 58, in
bot.polling(none_stop=True)
File "E:\code\cityBot\liber\lib\site-packages \telebot\__init__.py", line 664, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "E:\code\cityBot\liber\lib\site-packages\telebot\__init__.py", line 726, in __threaded_polling
raise e
File "E:\code\cityBot\liber\lib\site-packages\telebot\__init__.py", line 686, in __threaded_polling
self.worker_pool.raise_exceptions()
File "E:\code\cityBot\liber\lib\site-packages\telebot\util.py", line 135, in raise_exceptions
raise self.exception_info
File "E:\code\cityBot\liber\lib\site-packages\telebot\util.py", line 87, in run
task(*args, **kwargs)
File "E:\code\cityBot\bot.py", line 43, in callback_query
if usl.data == "kv":
AttributeError: 'function' object has no attribute 'data'
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
@ bot.callback_query_handler (func = lambda call: True)
def callgps (call):
if call.data == "kv":
bot.send_message (call.message.chat.id, text = "Apartment. Answer recorded.")
elif call.data == "of":
bot.send_message (call.message.chat.id, text = "Office. Answer recorded.")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question