Answer the question
In order to leave comments, you need to log in
How to edit a message sent by a bot?
Help me edit my post. I set the bot to send a picture with a caption and attached inline buttons in one message. How can I replace the image, the text for it and the button when I click on the button? Here is part of the code:
@bot.message_handler(commands=['start'])
def start_msg(message):
keyboard = types.InlineKeyboardMarkup(row_width=1)
one = types.InlineKeyboardButton('1', callback_data='one')
two = types.InlineKeyboardButton('2', callback_data='two')
three = types.InlineKeyboardButton('3', callback_data='three')
keyboard.add(one, two, three)
bot.send_photo(message.chat.id, 'AgACAgIAAxkDAAIB5GC-NXY5xQjMHR-sYdvZ9iqHGj38AAIKtTEbV1nxSQW3xZ3j3DnT-Eo0ny4AAwEAAwIAA3kAA58GBQABHwQ', caption = 'Вывод inline-клавиатуры', reply_markup=keyboard)
#обработка callback клавиатуры
@bot.callback_query_handler(func=lambda message: True)
def logic_inline(call):
if call.data == 'one':
bot.edit_message_caption(call.message.chat.id, 'Ты нажал на кнопку 1')
Answer the question
In order to leave comments, you need to log in
For edit_message_caption
you need to specify the text, chat ID and message ID. You don't pass the message ID, which message should the bot edit?
https://github.com/eternnoir/pyTelegramBotAPI/blob...
bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption='Ты нажал на кнопку 1')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question