Created
March 4, 2020 20:37
-
-
Save rokibhasansagar/d727fb30ef5a274cf536bea73260887c to your computer and use it in GitHub Desktop.
Kick all the deleted accounts from a telegram chat using telethon.
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 import TelegramClient | |
from telethon.tl.functions.channels import EditBannedRequest | |
from telethon.tl.types import ChatBannedRights | |
import asyncio | |
import datetime | |
api_id = 1234 # Your API_ID | |
api_hash = "1a2b3c456" # Your APP_ID | |
async def clear_chat(client): | |
group = input("Enter the group username where the script should search for deleted accounts: ") | |
deleted_accounts = 0 | |
async for user in client.iter_participants(group): | |
if user.deleted: | |
try: | |
deleted_accounts += 1 | |
await client(EditBannedRequest(group, user, ChatBannedRights( | |
until_date=datetime.timedelta(minutes=1), | |
view_messages=True | |
))) | |
except Exception as exc: | |
print(f"Failed to kick one deleted account because: {str(exc)}") | |
if deleted_accounts: | |
print(f"Kicked {deleted_accounts} Deleted Accounts") | |
else: | |
print(f"No deleted accounts found in {group}") | |
with TelegramClient("deleteacc", api_id, api_hash) as client: | |
asyncio.get_event_loop().run_until_complete(clear_chat(client)) |
Hi, Thanks for writing this script, works perfectly! I had been trying to run is within Spyder but with errors. However, when running from the CLI, calling directly from Python, it worked. Awesome, thanks again!
Glad to know it still works.
Well, I didn't write this code, but got it from somewhere on the net.
Although I forgot to mention the source here and eventually it is left as is.
hi ,
Currently this code says so, can you fix it?
DeprecationWarning: There is no current event loop
asyncio.get_event_loop().run_until_complete(clear_chat(client))
I'm getting errors here:
with TelegramClient ()"deleteacc"*, api_key, "api_hash) as client:
(asyncio.get_event_loop).run_until_complete(clear_chat(client))
Please help
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for writing this script, works perfectly! I had been trying to run is within Spyder but with errors. However, when running from the CLI, calling directly from Python, it worked. Awesome, thanks again!