Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telethon: how to get invite link to private channel?

In 1.5 version I did so:

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

But it doesn't work now:

ImportError: cannot import name 'ExportInviteRequest'

How to do it now?

like image 770
strannik-j Avatar asked Nov 24 '25 23:11

strannik-j


1 Answers

Raw API is subject to change between minor versions of the library, so the function you're trying to access no longer exists where it used to be.

Whenever this happens, you can search for the method again to find out where the new one is:

from telethon.tl.functions.messages import ExportChatInviteRequest

Usage is still the same:

from telethon.sync import TelegramClient

with TelegramClient(name, api_id, api_hash) as client:
    client(functions.messages.ExportChatInviteRequest(
        ChannelID
    ))

You also don't need to construct the InputPeer yourself, it's done automatically.

like image 102
Lonami Avatar answered Nov 27 '25 13:11

Lonami



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!