y0u4r3w3
y0u4r3w3

Reputation: 77

pyTelegramBotAPI message editing

I'm using pyTelegramBotAPI library for my bot and i need to handle message edits (whenever message in the chat is being edited), but i can't figure out how to do it from the documentation.

Also, when i tried to simply edit a message, that already was in the chat, i got this error:

2020-12-22 05:07:36,389 (__init__.py:489 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message can't be edited"

I'm really confused on those 2 topics, does anyone know the solution? :(

Thanks in advance!

Upvotes: 1

Views: 9378

Answers (1)

y0u4r3w3
y0u4r3w3

Reputation: 77

Okay, it's just me being dumb, but could be helpful for someone.

For handling message updates use:

@bot.edited_message_handler(func=lambda message: True)
def handler_function(message):
    # some stuff

This will handle message updates, for different types of messages, just change content_types in the handler.

Okay, now about updating messages from other users, you can't do it. For example, i send a message to my bot and want him to edit it, nope. Seems like, it's not possible in any way.

But your bot can edit his own messages, like that:

bot.edit_message_text(chat_id=CHAT_WITH_MESSAGE, text=NEW_TEXT, message_id=MESSAGE_TO_EDIT)

Alright, good luck! <3

Upvotes: 2

Related Questions