简体   繁体   English

Python, Telethon 发送专辑

[英]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

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()

There is send_file which sayssend_file

file (...): To send an album, you should provide a list in this parameter. file (...): 要发送专辑,您应该在此参数中提供一个列表。 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.如果提供了列表或类似内容,则其中的文件将按照它们出现的顺序作为专辑发送,如果提供的文件超过 10 个,则将其切成 10 个块。

caption (str, optional): Optional caption for the sent media message. caption (str, optional):已发送媒体消息的可选标题。 When sending an album, the caption may be a list of strings, which will be assigned to the files pairwise.发送专辑时,标题可能是一个字符串列表,将成对分配给文件。

So extending @Tibebes answer所以扩展@Tibebes 答案

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))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM