EditMessageRequest
Both users and bots can use this method. See code examples.
---functions--- messages.editMessage#48f71778 flags:# no_webpage:flags.1?true peer:InputPeer id:int message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.15?date = Updates
Returns
Updates |
This type can be an instance of either:
UpdateShort | UpdateShortChatMessage |
UpdateShortMessage | UpdateShortSentMessage |
Updates | UpdatesCombined |
UpdatesTooLong |
Parameters
peer | InputPeer | Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
id | int | |
no_webpage | flag | This argument defaults to None and can be omitted. |
message | string | This argument defaults to None and can be omitted. |
media | InputMedia | This argument defaults to None and can be omitted. |
reply_markup | ReplyMarkup | This argument defaults to None and can be omitted. |
entities | MessageEntity | This argument defaults to None and can be omitted. Otherwise, a list must be supplied. |
schedule_date | date | This argument defaults to None and can be omitted. |
Known RPC errors
This request can cause 14 known errors:
ChannelInvalidError | Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited. |
ChannelPrivateError | The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it. |
ChatWriteForbiddenError | You can't write in this chat. |
InlineBotRequiredError | The action must be performed through an inline bot callback. |
InputUserDeactivatedError | The specified user was deleted. |
MediaGroupedInvalidError | . |
MediaNewInvalidError | The new media to edit the message with is invalid (such as stickers or voice notes). |
MediaPrevInvalidError | The old media cannot be edited with anything else (such as stickers or voice notes). |
MessageAuthorRequiredError | Message author required. |
MessageEditTimeExpiredError | You can't edit this message anymore, too much time has passed since its creation.. |
MessageEmptyError | Empty or invalid UTF-8 message was sent. |
MessageIdInvalidError | The specified message ID is invalid or you can't do that operation on such message. |
MessageNotModifiedError | Content of the message was not modified. |
PeerIdInvalidError | An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations). |
You can import these from telethon.errors
.
Example
Please refer to the documentation of client.edit_message()
to learn about the parameters and see several code examples on how to use it.
The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.
from telethon.sync import TelegramClient from telethon import functions, types with TelegramClient(name, api_id, api_hash) as client: result = client(functions.messages.EditMessageRequest( peer='username', id=42, no_webpage=True, message='Hello there!', media=types.InputMediaUploadedPhoto( file=client.upload_file('/path/to/file.jpg'), spoiler=True, stickers=[types.InputDocument( id=-12398745604826, access_hash=-12398745604826, file_reference=b'arbitrary\x7f data \xfa here' )], ttl_seconds=42 ), schedule_date=datetime.datetime(2018, 6, 25) )) print(result.stringify())