Inline кнопки в ТГ боте на telebot
Мне нужно сделать так, чтобы после нажатия на одну Inline кнопку вызывался следующий блок кнопок.
Проблема: следующий блок кнопок не работает.
Вот код:
import telebot
from telebot import types
bot = telebot.TeleBot('Token')
@bot.message_handler(commands=['start'])
def send_welcome(message):
markup = types.InlineKeyboardMarkup(row_width=2)
itmbtn1 = types.InlineKeyboardButton(text='Connect a new channel', callback_data='1')
itmbtn2 = types.InlineKeyboardButton(text='Subscribtion', callback_data='2')
itmbtn3 = types.InlineKeyboardButton(text='Button 3', callback_data='3')
itmbtn4 = types.InlineKeyboardButton(text='Button 4', callback_data='4')
markup.add (itmbtn1, itmbtn2, itmbtn3, itmbtn4)
bot.send_photo (message.chat.id, photo=open('Path', 'rb'), caption="Good to see you! It's ChanellManagerBot!", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def answer(call):
global KeyboardData
if call.data == '1':
KeyboardData = 1
elif call.data == '2':
KeyboardData = 2
elif call.data == '3':
KeyboardData = 3
elif call.data == '4':
KeyboardData = 4
if call.data == '1':
bot.send_message (call.message.chat.id, "Assigning bot as a channel administrator: \n1) Open chanell settings \n2) Open 'Administrators' tab \n3) Click 'Add administrator' and paste 'Bot_Name' \nBot connected!")
elif call.data == '2':
NumPerWeek = 0
markup2 = types.InlineKeyboardMarkup(row_width=2)
itmbtn5 = types.InlineKeyboardButton(text='3', callback_data='5', KeyboardData = 5)
itmbtn6 = types.InlineKeyboardButton(text='5', callback_data='6', KeyboardData = 6)
itmbtn7 = types.InlineKeyboardButton(text='7', callback_data='7', KeyboardData = 7)
itmbtn8 = types.InlineKeyboardButton(text='14', callback_data='8', KeyboardData = 8)
itmbtn9 = types.InlineKeyboardButton(text='Custom', callback_data='9', KeyboardData = 9)
markup2.add (itmbtn5, itmbtn6, itmbtn7, itmbtn8, itmbtn9)
bot.send_message (call.message.chat.id, 'Select number of posts per week:', reply_markup=markup2)
while NumPerWeek == 0:
if KeyboardData == 5:
NumPerWeek = 3
elif KeyboardData == 6:
NumPerWeek = 5
elif KeyboardData == 7:
NumPerWeek = 7
elif KeyboardData == 8:
NumPerWeek = 14
else:
pass
if NumPerWeek != 0:
bot.send_message (call.message.chat.id, f"Selected - {NumPerWeek}")
bot.infinity_polling()