-
-
Save casper/444daf52c1fde5a1b839306b551f757f to your computer and use it in GitHub Desktop.
Telethon get Telegram chat ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In reference to | |
# https://stackoverflow.com/a/60982206/823617 | |
# 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: | |
print(get_display_name(dialog.entity), dialog.entity.id) | |
client.loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment