Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Telethon send album

I can't make a script for a long time. I have one telegram channel, I don't want to resend an album from this channel, but just send it to me in one message

from telethon import TelegramClient, events
from telethon import events

api_id = 
api_hash = ""

chat = ''

client = TelegramClient('', api_id, api_hash)

print('started')

@client.on(events.Album)
async def handler(event):
 #what farther
like image 897
MXSNK Avatar asked Oct 25 '25 02:10

MXSNK


2 Answers

Here is one approach to do that:

from telethon import TelegramClient, events

api_id = ...
api_hash = ' ... '

chat = -1001277xxxxxx

client = TelegramClient('session', api_id, api_hash)

@client.on(events.Album)
async def handler(event):

    # craft a new message and send
    await client.send_message(
        chat,
        file=event.messages, # event.messages is a List - meaning we're sending an album
        message=event.original_update.message.message,  # get the caption message from the album
    )

    ## or forward it directly
    # await event.forward_to(chat)

client.start()
client.run_until_disconnected()
like image 101
Tibebes. M Avatar answered Oct 27 '25 17:10

Tibebes. M


There is send_file which says

file (...): To send an album, you should provide a list in this parameter. If a list or similar is provided, the files in it will be sent as an album in the order in which they appear, sliced in chunks of 10 if more than 10 are given.

caption (str, optional): Optional caption for the sent media message. When sending an album, the caption may be a list of strings, which will be assigned to the files pairwise.

So extending @Tibebes answer

await client.send_file( # Note this is send_file not send_message
    chat,
    file=event.messages
    caption=list(map(lambda a: str(a.message), event.messages))
)
like image 31
Phani Rithvij Avatar answered Oct 27 '25 17:10

Phani Rithvij



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!