![](/img/trans.png)
[英]how to get messages from linked discussion group of channels with telethon
[英]how to get channelname from channels using telethon
我想獲取電報頻道的用戶名。 我已經給出了channel_id。 我試圖通過 get_entity 得到它,比如:
channelData = await client.get_entity(channelId)
print(channelData.username)
它適用於某些頻道。 但是對於例如 1628748088 我只是在用戶名字段中得到 None 。 所以我嘗試了 FullChannelRequest,但正如您在 Docs 中看到的那樣,沒有用戶名屬性https://tl.telethon.dev/constructors/channel_full.html
我想從 GetHistoryRequest 和 NewMessage 事件中獲取 tue channelName。 有沒有辦法為所有頻道獲取此屬性?
你可以像這樣得到 cahnel 的名字和 id:
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}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.