Skip to content

Instantly share code, notes, and snippets.

@dolohow
Last active March 4, 2023 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolohow/1fb72c317ead1a93e6da6f60946c7887 to your computer and use it in GitHub Desktop.
Save dolohow/1fb72c317ead1a93e6da6f60946c7887 to your computer and use it in GitHub Desktop.
Delete old telegram bot messages from group chat and user commands
#!/usr/bin/python
# Prerequisities
# pip install pyrogram tgcrypto
from datetime import datetime
from pyrogram import Client
# Configure here
api_id =
api_hash = ''
delete_older_than_days = 1
chat_id = ''
app = Client("my_account", api_id, api_hash)
async def main():
now = datetime.now()
i = 0
async with app:
async for message in app.get_chat_history(chat_id):
message_age = (now - message.date).days
if not message.service and message_age >= delete_older_than_days:
if message.from_user.is_bot or (message.text and message.text.startswith('/')):
i += 1
await message.delete()
print(f'Deleted {i}')
app.run(main())
@Januarius93
Copy link

WHERE ARE THE TESTS???111??!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment