UploadMediaRequest
Both users and bots can use this method. See code examples.
---functions--- messages.uploadMedia#519bc2b1 peer:InputPeer media:InputMedia = MessageMedia
Returns
MessageMedia |
This type can be an instance of either:
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.). |
media | InputMedia |
Known RPC errors
This request can cause 3 known errors:
BotMissingError | This method can only be run by a bot. |
MediaInvalidError | Media invalid. |
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.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.UploadMediaRequest( 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 ) )) print(result.stringify())