Skip to content

Instantly share code, notes, and snippets.

Created February 25, 2024 10:00
Show Gist options
  • Save Foadsf/15d34af28057d1b42c825cda75035ab1 to your computer and use it in GitHub Desktop.
Save Foadsf/15d34af28057d1b42c825cda75035ab1 to your computer and use it in GitHub Desktop.
Efficiently manage and display your Telegram groups with our Python script. Designed for Telegram users and group administrators, this script leverages the Telethon library to fetch and print a list of groups you own directly to your console. Perfect for organization and quick access, this tool simplifies group management on Telegram—ideal for d…
api_id = YOUR_API_ID
api_hash = YOUR_API_HASH
phone_number = YOUR_PHONE_NUMBER
password = YOUR_PASSWORD
import configparser
from telethon.sync import TelegramClient
from import Channel, Chat
# Load the configuration
config = configparser.ConfigParser()"config.ini")
# Extract the API ID and hash
api_id = config["telegram"]["api_id"]
api_hash = config["telegram"]["api_hash"]
phone_number = config["telegram"]["phone_number"]
password = config.get(
"telegram", "password", fallback=None, raw=True
) # None if not exists
# Optionally, print phone number and password if needed
print(f"Phone Number: {phone_number}")
if password:
print(f"Password: {password}")
with TelegramClient("anon", api_id, api_hash) as client:
for dialog in client.iter_dialogs():
if isinstance(dialog.entity, (Channel, Chat)):
# For supergroups and channels
if isinstance(dialog.entity, Channel) and dialog.entity.megagroup:
# Check if you are the creator or have admin rights
if dialog.entity.creator or (
and dialog.entity.admin_rights.add_admins
f"Group/Channel: {} | ID: {} | Access Hash: {dialog.entity.access_hash}"
except AttributeError:
# In case admin_rights are not present which shouldn't happen for admins but just in case
# For basic groups (not supergroups)
elif isinstance(dialog.entity, Chat):
print(f"Basic Group: {} | ID: {}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment