Skip to content

Instantly share code, notes, and snippets.

@liyanasahir
Last active December 9, 2024 19:35
Show Gist options
  • Save liyanasahir/1411b833d0dcfbf7f5533aa058c3bbfa to your computer and use it in GitHub Desktop.
Save liyanasahir/1411b833d0dcfbf7f5533aa058c3bbfa to your computer and use it in GitHub Desktop.
Extracting subscribers list of a Telegram Channel
from telethon import TelegramClient, sync
# Use your own values here
api_id = '123456'
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
channel = 'channel_name'
client = TelegramClient('Session_details', api_id, api_hash)
phone_number='9199999999'
client.connect()
print("Connected")
if not client.is_user_authorized():
client.send_code_request(phone_number)
me = client.sign_in(phone_number, input('Enter code: '))
# get all the users and print them
for u in client.iter_participants(channel, aggressive=True):
print(u.id, u.first_name)
client.disconnect()
print("Disconnected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment