Answer the question
In order to leave comments, you need to log in
How to get text on inline button in pytelegrambotapi?
Hello, how do I get the text written on an inline button in pytelegrambotapi?
Answer the question
In order to leave comments, you need to log in
Everything depends on the task. If you need the text of the button that the user clicked on, then the code will be as follows (in this case, the button must have the callback_data parameter , otherwise we will not be able to get the unique name of the button):
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
for row in call.message.json['reply_markup']['inline_keyboard']:
if call.data==row[0]['callback_data']:
print(f'Текст на нажатой кнопке: {row[0]["text"]}')
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
for row in call.message.json['reply_markup']['inline_keyboard']:
print(row[0]['text'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question