Skip to content

Instantly share code, notes, and snippets.


casper/ Secret

Last active Feb 16, 2021
What would you like to do?
Telethon get Telegram chat ID
# In reference to
# You need a previous Telethon .session file (from some other bot) for this code to work.
import os
import sys
from telethon import TelegramClient
from telethon.utils import get_display_name
session_name = "session_file_name"
api_id = "id"
api_hash = "hash"
dialog_count = 10 # you may change this
client = TelegramClient(session_name, api_id, api_hash)
async def main():
await client.connect()
dialogs = await client.get_dialogs(dialog_count)
for dialog in dialogs:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment