edit_message_media()¶
- Client.edit_message_media(chat_id: int | str, message_id: int, media: InputMedia, show_caption_above_media: bool | None = None, schedule_date: datetime | None = None, business_connection_id: str | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message¶
Edit animation, audio, document, photo or video messages, or to add media to text messages.
If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. Otherwise, the message type can be changed arbitrarily.
Usable by ✅ Users ✅ BotsNote
Business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
- Parameters:
chat_id (
int|str) – Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use “me” or “self”. For a contact that exists in your Telegram address book you can use his phone number (str).message_id (
int) – Message identifier in the chat specified in chat_id.media (
InputMedia) – One of the InputMedia objects describing an animation, audio, document, photo or video.show_caption_above_media (
bool, optional) – Pass True, if the caption must be shown above the message media.schedule_date (
datetime, optional) – Date when the message will be automatically sent.business_connection_id (
str, optional) – Unique identifier of the business connection on behalf of which the message will be sent.reply_markup (
InlineKeyboardMarkup, optional) – An InlineKeyboardMarkup object.file_name (
str, optional) – File name of the media to be sent. Not applicable to photos. Defaults to file’s path basename.
- Returns:
Message– On success, the edited message is returned.
Example
from ftmgram.types import InputMediaPhoto, InputMediaVideo, InputMediaAudio # Replace the current media with a local photo await app.edit_message_media(chat_id, message_id, InputMediaPhoto("new_photo.jpg")) # Replace the current media with a local video await app.edit_message_media(chat_id, message_id, InputMediaVideo("new_video.mp4")) # Replace the current media with a local audio await app.edit_message_media(chat_id, message_id, InputMediaAudio("new_audio.mp3"))