Telethon:如何获取私人频道的邀请链接?

str*_*k-j 3 python telethon

在 1.5 版本中我是这样做的:

from telethon.tl.functions.channels import ExportInviteRequest
from telethon.tl.types import InputChannel, InputPeerChannel
ChannelLink = Client(ExportInviteRequest(
    InputPeerChannel(channel_id=ChannelID,
        access_hash=ChannelHash))).link
Run Code Online (Sandbox Code Playgroud)

但现在不起作用:

ImportError: cannot import name 'ExportInviteRequest'
Run Code Online (Sandbox Code Playgroud)

现在该怎么做呢?

Lon*_*ami 5

原始 API 可能会在库的次要版本之间发生变化,因此您尝试访问的函数不再存在于以前的位置。

每当发生这种情况时,您都可以再次搜索该方法以找出新的方法在哪里:

from telethon.tl.functions.messages import ExportChatInviteRequest
Run Code Online (Sandbox Code Playgroud)

用法还是一样:

from telethon.sync import TelegramClient

with TelegramClient(name, api_id, api_hash) as client:
    client(functions.messages.ExportChatInviteRequest(
        ChannelID
    ))
Run Code Online (Sandbox Code Playgroud)

您也不需要InputPeer自己构建,它会自动完成。