A
A
Asriel2021-06-07 18:23:05
Python
Asriel, 2021-06-07 18:23:05

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')


When the button is pressed, TeleBot issues: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found" (translation: "TeleBot: "The request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: Chat Not Found""). How can I make a request to change the signature. And it is desirable to help with editing buttons and pictures

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-07
@Asriel

For edit_message_captionyou 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 question

Ask a Question

731 491 924 answers to any question