from telethon import TelegramClient
from telethon.tl.types import Channel
# Remember to use your own values from my.telegram.org!
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
client = TelegramClient('anon', api_id, api_hash)
async def main():
# Getting information about yourself
me = await client.get_me()
# "me" is a user object. You can pretty-print
# any Telegram object with the "stringify" method:
print(me.stringify())
# You can print all the dialogs/conversations that you are part of:
print("You are subscribed to following channels:")
async for dialog in client.iter_dialogs(limit=None):
if isinstance(dialog.entity, Channel):
print('Channel ', dialog.name, 'has ID', dialog.id)
with client:
client.loop.run_until_complete(main())
from telethon import TelegramClient
from telethon.tl.types import Channel
import asyncio
async def main():
async with TelegramClient('anon', '2234242', 'e40gte4t63636423424325a57') as client:
# For each dialog
async for dialog in client.iter_dialogs(limit = None):
# If this is a Channel
if isinstance(dialog.entity, ( Channel )):
# Log
dialogType = type(dialog.entity)
print(f'{dialog.title:<42}\t{dialog.id}')
asyncio.run(main())
2条答案
按热度按时间whlutmcx1#
您可以使用Python telethon库,该库允许您通过帐户以编程方式执行操作。
这是Quick Start的最小化代码,可以打印你所有的聊天记录,你可以做任何你需要的过滤或处理,即使你想在那里写点什么。
eanckbw92#
是否有办法获得我是Telegram***(最好是Telegram Desktop)*中的成员的频道列表?
官方的Telegram Bot API没有获取通道成员的选项,所以使用Telegrams MTPROTO创建自己的客户端是获取这些数据的唯一合法方法。
正如所说,你可以刮Telegram Web Version,但这很可能会改变一段时间很快,你需要编辑你的刮刀。
Telethon似乎是一个有效/稳定的解决方案,请继续阅读自定义示例脚本
有没有办法获得我在Telegram(最好是Telegram Desktop)中是会员的频道**的列表?
如果只想知道自己是哪个频道的成员,可以使用
dialog.entity
检查当前频道是否为Channel
类型1.使用
client.iter_dialogs()
在每个通道上循环isinstance
检查它是否为Channel
User
(聊天)ChatForbidden
(聊天被您踢出)将输出类似于