簡體   English   中英

Python, Telethon 發送專輯

[英]Python, Telethon send album

好久沒寫劇本了我有一個電報頻道,我不想從這個頻道重新發送專輯,但只需在一條消息中發送給我

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

這是一種方法:

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

send_file

file (...): 要發送專輯,您應該在此參數中提供一個列表。 如果提供了列表或類似內容,則其中的文件將按照它們出現的順序作為專輯發送,如果提供的文件超過 10 個,則將其切成 10 個塊。

caption (str, optional):已發送媒體消息的可選標題。 發送專輯時,標題可能是一個字符串列表,將成對分配給文件。

所以擴展@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