skip to Main Content

Is there a way to get a list of channels I’m a member of in Telegram (preferably Telegram Desktop)?
I may be able to come up with a solution using JS in the browser or even Selenium, but isn’t there a more ergonomic approach that would work in Telegram Desktop (like an API)?

If it matters I’m running Telegram as a snap application on Ubuntu 20.04.

2

Answers


  1. You can use Python telethon library that allows you to act programmatically from your account.

    Here is minimized code from Quick Start that allows to print all of your chats. There you can do whatever filtering or processing you need.
    Even if you’ll want to write something there.

    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())
    
    Login or Signup to reply.
  2. Is there a way to get a list of channels I’m a member of in Telegram (preferably Telegram Desktop)?

    Well, the official Telegram Bot API does not have an option to get members of a channel. So using Telegrams MTPROTO to make your own client that will do this is the only legit way of retreiving this data.

    As said, you could scrape the Telegram Web Version, but thats most likely to change some time soon which you’ll need to edit your scraper.

    Telethon seems like a valid/stable solution, continue reading for a custom example script


    Is there a way to get a list of channels I’m a member of in Telegram (preferably Telegram Desktop)?

    If you just want to know what channels you’re member of, you can use the dialog.entity to check if the current one is of type Channel

    1. Use client.iter_dialogs() to loop over each channel
    2. Use isinstance to check if it’s a Channel
      • This will make sure we don’t log for types like:
        • User (chats)
        • ChatForbidden (Chats your kicked out off)

    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())
    

    Will output something like

    channel_1           <channel_id>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search