SendMediaRequest

Both users and bots can use this request. See code examples.

---functions---
messages.sendMedia#7bd66041 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true invert_media:flags.16?true peer:InputPeer reply_to:flags.0?InputReplyTo media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?date send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut = Updates

Returns

Updates

This type can be an instance of either:

UpdateShortUpdateShortChatMessage
UpdateShortMessageUpdateShortSentMessage
UpdatesUpdatesCombined
UpdatesTooLong

Parameters

peerInputPeerAnything entity-like will work if the library can find its Input version (e.g., usernames, Peer, User or Channel objects, etc.).
mediaInputMedia
messagestring
silentflagThis argument defaults to None and can be omitted.
backgroundflagThis argument defaults to None and can be omitted.
clear_draftflagThis argument defaults to None and can be omitted.
noforwardsflagThis argument defaults to None and can be omitted.
update_stickersets_orderflagThis argument defaults to None and can be omitted.
invert_mediaflagThis argument defaults to None and can be omitted.
reply_toInputReplyToThis argument defaults to None and can be omitted.
random_idlongIf left unspecified, it will be inferred automatically.
reply_markupReplyMarkupThis argument defaults to None and can be omitted.
entitiesMessageEntityThis argument defaults to None and can be omitted. Otherwise, a list must be supplied.
schedule_datedateThis argument defaults to None and can be omitted.
send_asInputPeerThis argument defaults to None and can be omitted. Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer, User or Channel objects, etc.).
quick_reply_shortcutInputQuickReplyShortcutThis argument defaults to None and can be omitted.

Known RPC errors

This request can cause 45 known errors:

BotPaymentsDisabledErrorThis method can only be run by a bot.
BotPollsDisabledErrorYou cannot create polls under a bot account.
BroadcastPublicVotersForbiddenErrorYou cannot broadcast polls where the voters are public.
ChannelInvalidErrorInvalid 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.
ChannelPrivateErrorThe channel specified is private and you lack permission to access it. Another reason may be that you were banned from it.
ChatAdminRequiredErrorChat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group.
ChatSendMediaForbiddenErrorYou can't send media in this chat.
ChatWriteForbiddenErrorYou can't write in this chat.
CurrencyTotalAmountInvalidErrorThe total amount of all prices is invalid.
EmoticonInvalidErrorThe specified emoticon cannot be used or was not a emoticon.
EntityBoundsInvalidErrorSome of provided entities have invalid bounds (length is zero or out of the boundaries of the string).
ExternalUrlInvalidErrorExternal URL invalid.
FilePartsInvalidErrorThe number of file parts is invalid.
FilePartLengthInvalidErrorThe length of a file part is invalid.
FileReferenceEmptyErrorThe file reference must exist to access the media and it cannot be empty.
FileReferenceExpiredErrorThe file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent.
GameBotInvalidErrorYou cannot send that game with the current bot.
InputUserDeactivatedErrorThe specified user was deleted.
MediaCaptionTooLongErrorThe caption is too long.
MediaEmptyErrorThe provided media object is invalid or the current account may not be able to send it (such as games as users).
PaymentProviderInvalidErrorThe payment provider was not recognised or its token was invalid.
PeerIdInvalidErrorAn invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations).
PhotoExtInvalidErrorThe extension of the photo is invalid.
PhotoInvalidDimensionsErrorThe photo dimensions are invalid (hint: `pip install pillow` for `send_file` to resize images).
PhotoSaveFileInvalidErrorThe photo you tried to send cannot be saved by Telegram. A reason may be that it exceeds 10MB. Try resizing it locally.
PollAnswersInvalidErrorThe poll did not have enough answers or had too many.
PollOptionDuplicateErrorA duplicate option was sent in the same poll.
PollQuestionInvalidErrorThe poll question was either empty or too long.
PostponedTimeoutErrorThe postponed call has timed out.
QuizCorrectAnswersEmptyErrorA quiz must specify one correct answer.
QuizCorrectAnswersTooMuchErrorThere can only be one correct answer.
QuizCorrectAnswerInvalidErrorThe correct answer is not an existing answer.
QuizMultipleInvalidErrorA poll cannot be both multiple choice and quiz.
RandomIdDuplicateErrorYou provided a random ID that was already used.
ScheduleDateTooLateErrorThe date you tried to schedule is too far in the future (last known limit of 1 year and a few hours).
ScheduleTooMuchErrorYou cannot schedule more messages in this chat (last known limit of 100 per chat).
StorageCheckFailedErrorServer storage check failed.
TimeoutErrorA timeout occurred while fetching data from the worker.
TopicDeletedErrorThe topic was deleted.
UserBannedInChannelErrorYou're banned from sending messages in supergroups/channels.
UserIsBlockedErrorUser is blocked.
UserIsBotErrorBots can't send messages to other bots.
VideoContentTypeInvalidErrorThe video content type is not supported with the given parameters (i.e. supports_streaming).
WebpageCurlFailedErrorFailure while fetching the webpage with cURL.
WebpageMediaEmptyErrorWebpage media empty.

You can import these from telethon.errors.

Example

Please refer to the documentation of client.send_file() 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.SendMediaRequest(
        peer='username',
        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
        ),
        message='Hello there!',
        noforwards=True,
        update_stickersets_order=True,
        invert_media=True,
        reply_to=types.InputReplyToMessage(
            reply_to_msg_id=42,
            top_msg_id=42,
            reply_to_peer_id='username',
            quote_text='some string here',
            quote_entities=[types.MessageEntityUnknown(
                offset=42,
                length=42
            )],
            quote_offset=42
        ),
        schedule_date=datetime.datetime(2018, 6, 25),
        send_as='username',
        quick_reply_shortcut=types.InputQuickReplyShortcut(
            shortcut='some string here'
        )
    ))
    print(result.stringify())