I’m trying to get the invite link of a public channel and a public group.
I tried using the ExportChatInviteRequest function but it raises a ChatAdminRequiredError.
The thing I don’t understand is why can I see and get the invite link of a public channel group with the telegram app but can’t get it with telethon?
I use version 1.26.1:
from telethon.tl.functions.messages import ExportChatInviteRequest
async def main():
chat = await client.get_entity('https://t.me/bestmemes')
invite = await client(ExportChatInviteRequest(chat))
print(invite)
raises:
telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by ExportChatInviteRequest)
can someone help me, please?
I can see the invite of the given channel via the telegram app:
2
Answers
I did this:
App api_id
andApp api_hash
The
ExportChatInviteRequest
method you are trying to use creates a private chat link. Obviously you can’t do this if you’re not an administratorHere is a small code example that gets links to all open chats
I would like to add some explanation about
hasattr(chat, 'username')
. For some chats you will havehttps://t.me/None
. These are just the same closed chats that do not have an open link to join. But theExportChatInviteRequest
function will not work for these chats either, because it CREATES a link, and does not receive it. And if you are not an administrator in this chat you will get an error