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?
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}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With