Answer the question
In order to leave comments, you need to log in
How does bot.edit_message_text work in python telegram bot?
There is a handler that calls a function and there is a function that performs a series of actions and sends a message with an inline keyboard.
def make_b(message, namber_bort):
key = telebot.types.InlineKeyboardMarkup()
but = telebot.types.InlineKeyboardButton(text="бла-бла", callback_data=5)
key.add(but)
bot.edit_message_text(message.chat_id, text="тру-ту-ту", reply_markup=key )
@bot.message_handler(content_types=['text'])
def handle_text(message):
if message.text==5
make_b(message, namber_bort)
bot.send_message(message.chat.id, text="тру-ту-ту", reply_markup=key)
AttributeError: 'Message' object has no attribute 'chat_id'
(__init__.py:418 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400," description":"Bad Request: chat not found"}']"
AttributeError: 'Chat' object has no attribute 'get'
Answer the question
In order to leave comments, you need to log in
I found a solution:
bot.edit_message_text only works to change an existing message, so it is logical that it should be placed only in @bot.callback_query_handler.
In the edit_message_text method, you must specify the chat id chat_id and message id message_id .
Try like this:
bot.edit_message_text(chat_id=message.chat.id, message_id=message.message_id, text="тру-ту-ту", reply_markup=key )
bot.edit_message_text does not have to be placed only in @bot.callback_query_handler, you can write the message to a variable, and then take the message_id from it and edit the message.
messagetoedit = bot.send_message(message.chat.id, 'Текст')
bot.edit_message_text(chat_id=message.chat.id, message_id=messagetoedit.message_id, text=f"Новый текст")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question