Телеграм бот. При нажатии на кнопку выдаётся ответ. Бот должен выводить все кнопки после каждого ответа
import random
import telebot
bot = telebot.TeleBot('00000000000000000000000');
from telebot import types
a = [""]
b = [""]
c = [""]
d = [""]
e = [""]
f = [""]
g = [""]
h = [""]
i = [""]
j = [""]
k = [""]
l = [""]
m = [""]
n = [""]
o = [""]
p = [""]
first = [a, b, c, e, f, g, h, i, j, k, l, m, n, o, p]
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
if message.text == "/start":
bot.send_message(message.from_user.id, "Привет")
keyboard = types.InlineKeyboardMarkup()
key_0 = types.InlineKeyboardButton(text='', callback_data= 'anslib')
keyboard.add(key_0)
key_0 = types.InlineKeyboardButton(text='', callback_data= 'anslib')
bot.send_message(message.from_user.id, text= '', reply_markup=keyboard)
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
if call.data == "anslib":
msg = random.choice(first)
bot.send_message(call.message.chat.id, msg)
bot.polling(none_stop=True, interval=0)
Ответы (1 шт):
Автор решения: Bor-is-luv
→ Ссылка
В get_text_messages во время отправки сообщения есть параметр reply_markup . Думаю надо сделать также и в callback_worker.
Стоит попробовать примерно следующее:
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
if call.data == "anslib":
keyboard = types.InlineKeyboardMarkup()
key_0 = types.InlineKeyboardButton(text='', callback_data='anslib')
keyboard.add(key_0)
msg = random.choice(first)
bot.send_message(call.message.chat.id, msg, reply_markup=keyboard)