Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get channelname from channels using telethon

I want to get the username of a telegram channel. I have given the channel_id. I tried to get it via get_entity like:

channelData = await client.get_entity(channelId)

print(channelData.username)

and it works for some channels. But for e.g. 1628748088 i just get None in username field. So I tried a FullChannelRequest, but as you can see in Docs, there is no username attribute https://tl.telethon.dev/constructors/channel_full.html

I want to get tue channelName from GetHistoryRequest and NewMessage Event. Is there any way to get this attribute for all channels?

like image 222
CampingCow Avatar asked Oct 22 '25 10:10

CampingCow


1 Answers

You can get the channel's name and id like this:

client = TelegramClient(session_name, api_id, api_hash)

for d in client.iter_dialogs():
   channelId = d.entity.id
   channelName = d.name
   print(f"channel id: {channelId}, channel name: {channelName}")
like image 156
Hamid Avatar answered Oct 25 '25 02:10

Hamid



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!