Telebot: How To Retrieve Inlinekeyboardbutton Callback Data?
I am buidling a simple game with pytelegrambotapi. According to the rules, the user is sent a definition and four buttons with words as text, of which one is correct. The user then
Solution 1:
Nevermind, I found an answer.
@bot.callback_query_handler(func=lambda call: True)
def handle_query(call):
if call.data.split('#')[0] == call.data.split('#')[1]:
bot.send_message(call.message.chat.id, '✅ Correct!')
else:
bot.send_message(call.message.chat.id, '❌ Wrong!\n♻️ The answer is: %s' % call.data.split('#')[1])
@bot.message_handler(commands=['game', 'g'])
def game(message):
list_of_words = load_my_dictionary(message.from_user.id)
random.shuffle(list_of_words)
while not len(list_of_words) < 4:
current = list_of_words.pop()
word = current[0]
definition = current[1]
all_answers = generate_answers(word, list_of_words)
keyboard = generate_keyboard(all_answers, word)
bot.send_message(message.from_user.id, definition, reply_markup = keyboard)
time.sleep(7)
bot.send_message(message.from_user.id, '📠List is empty!')
Post a Comment for "Telebot: How To Retrieve Inlinekeyboardbutton Callback Data?"