How to find username from id in telethon

Viewed 654

I wanted to know that can I find the username of a public telegram channel from it's public id in telethon?

I tried the get_entity method but it is only working for telegram group not channel.

So, how can I get the username ?

1 Answers

Try this,

 channel=-100XXXXXXX
 result = client(functions.channels.GetFullChannelRequest(
    channel=channel
  ))
  print(result.chats[0].username)

channel id should start with -100.

To find the username of a public channel using channel id, You should be a member of that particular public channel.

But, In public Channels, You can see the username in their link https://t.me/channel_username. You don't have to be a member of a channel, to see the username.

Related