Не работает callback_query_handler() в Python Telebot
Всем привет! Создаю двух-язычного (ru, en) тг бота. Ниже часть кода с проблемой:
@bot.message_handler(commands=['lang'])
def start_func(message):
markup = types.InlineKeyboardMarkup()
rus = types.InlineKeyboardButton('Русский 🇷🇺', callback_data='rus')
eng = types.InlineKeyboardButton('English 🇬🇧', callback_data='eng')
markup.row(rus, eng)
bot.send_message(message.chat.id, 'Please, choose the language you want to continue in below again 👇', reply_markup=markup)
@bot.callback_query_handler(func=lambda callback: True)
def language(callback):
if callback.data == 'rus':
markup1 = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton('Продолжить', callback_data='да')
markup1.add(btn1)
bot.edit_message_text(f'Привет, {callback.from_user.first_name}! Вы выбрали <b>Русский</b> 🇷🇺 язык. <b>Продолжить?</b> \n\nIf you want to change your choice, write /lang', callback.message.chat.id, callback.message.message_id, parse_mode='html', reply_markup=markup1)
elif callback.data == 'eng':
markup2 = types.InlineKeyboardMarkup()
btn2 = types.InlineKeyboardButton('Continue', callback_data='yes')
markup2.add(btn2)
bot.edit_message_text(f'Hello, {callback.from_user.first_name}! You chose <b>English</b> 🇬🇧 language. <b>Continue?</b> \n\nЕсли вы хотите изменить свой выбор, напишите /lang', callback.message.chat.id, callback.message.message_id, parse_mode='html', reply_markup=markup2)
@bot.callback_query_handler(func=lambda callback: True)
def choose_mood(message):
print(message)
text = f'Ещё раз привет, {message.from_user.first_name}, я - бот <b>Cool Pictures</b>! \n\nЯ помогу Вам найти интересные картинки по вашему вкусу. Для начала выберите настроение картинки из плиток в низу экрана.👇'
if message.data == 'да':
text = text
markup = types.ReplyKeyboardMarkup(row_width=2,resize_keyboard=True)
btn1r = types.KeyboardButton('Весёлое 😄')
btn2r = types.KeyboardButton('Нейтральное 😐')
btn3r = types.KeyboardButton('Грустное 😔')
markup.add(btn1r)
markup.add(btn2r)
markup.add(btn3r)
bot.send_message(message.from_user.id, text, parse_mode='html', reply_markup=markup)
elif message.data == 'yes':
text = translator.translate(text, crs='ru', dest='en').text
markup1 = types.ReplyKeyboardMarkup(row_width=2,resize_keyboard=True)
btn1e = types.KeyboardButton('Happy 😄')
btn2e = types.KeyboardButton('Neutral 😐')
btn3e = types.KeyboardButton('Sad 😔')
markup1.add(btn1e)
markup1.add(btn2e)
markup1.add(btn3e)
bot.send_message(message.from_user.id, text, parse_mode='html', reply_markup=markup1)
Дело в том, что Inline кнопка "Продолжить" появляется, но после её нажатия ничего не происходит, то есть не срабатывает функция "choose_mood". Что я делаю не так? Если понадобится полный код - пишите, я отредактирую! Всем заранее спасибо.