[Python] SendMultiMediaRequest fails silently when sending multiple files [Python/Telethon]

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use the SendMultiMediaRequest function from the Telethon library to send a Telegram message that includes several images and some text.

    However, the request doesn't work as expected — no message is sent. I'm not sure if I'm using it correctly, or if I'm missing something.

    Here is a simplified version of my code:


    # Cast to ensure proper data types for channel ID and access hash
    channel = InputPeerChannel(channel_id=int(channel_id), access_hash=int(access_hash))

    media_group = []
    # 'test.png', 'test2.png' are random and different png images
    for i, path in enumerate(['test.png', 'test2.png']):

    # Upload each image to Telegram
    uploaded_photo = await client.upload_file(path)
    if not uploaded_photo:
    raise RuntimeError(f"Failed to upload file: {path}")

    # Define the input media for each photo
    media = InputMediaUploadedPhoto(file=uploaded_photo)

    # Append the image to the media group
    media_group.append(InputSingleMedia(
    media=media,
    message=text_message if i == 0 else "", # Text only for the first image
    random_id=random.getrandbits(63) # Random ID for each media
    ))

    # Calculate the schedule time
    schedule_time = datetime.now() + timedelta(minutes=60)

    # Send the post as a message
    await client(SendMultiMediaRequest(
    peer=channel,
    multi_media=media_group,
    schedule_date=schedule_time
    ))


    Script output: ❌ Unexpected error occurred: Media invalid (caused by SendMultiMediaRequest)

    Questions:


    • Am I using SendMultiMediaRequest correctly?


    • How can I properly send multiple media items and a caption/text together?

    Continue reading...

Compartilhe esta Página