Last active
October 10, 2024 04:10
-
-
Save ronik56/67ff4e5eee46c501686e436060649e6a to your computer and use it in GitHub Desktop.
script to leave all telegram groups
This file contains hidden or 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
from telethon.sync import TelegramClient | |
from telethon.tl.functions.messages import GetDialogsRequest | |
from telethon.tl.types import InputPeerEmpty | |
# Go to https://my.telegram.org/apps, sign in, go to API development tools, create an app, copy and paste below: | |
api_id = 111111 | |
api_hash = '2o23o13k1o3131' | |
phone = '+123456789' | |
client = TelegramClient(phone, api_id, api_hash) | |
client.connect() | |
if not client.is_user_authorized(): | |
client.send_code_request(phone) | |
client.sign_in(phone, input('Enter the code: ')) # Enter the login code sent to your telegram | |
chats = [] | |
last_date = None | |
chunk_size = 200 | |
groups=[] | |
result = client(GetDialogsRequest( | |
offset_date=last_date, | |
offset_id=0, | |
offset_peer=InputPeerEmpty(), | |
limit=chunk_size, | |
hash = 0 | |
)) | |
chats.extend(result.chats) | |
""" | |
Megagroups are groups of more than 200 people, if you want to leave | |
smaller groups as well delete this part. If you want to stay in a few | |
specific groups, add their titles to the groups_to_exclude list. | |
""" | |
groups_to_exclude = ['group title'] | |
for chat in chats: | |
try: | |
if chat.megagroup== True and chat.title not in groups_to_exclude: | |
client.delete_dialog(chat) | |
except: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated verison