Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active December 20, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doorbash/c5abbf627bb838d1d4f112c1d898e021 to your computer and use it in GitHub Desktop.
Save doorbash/c5abbf627bb838d1d4f112c1d898e021 to your computer and use it in GitHub Desktop.
# 1. pip3 install telethon
# 2. Go to https://my.telegram.org/ and get api_id, api_hash
from telethon import TelegramClient, events, sync
import logging
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',level=logging.WARNING)
api_id = 12345
api_hash = 'PUT-YOUR-API-HASH-HERE'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
@client.on(events.NewMessage)
async def my_event_handler(event):
#is_from_someone = event.message.from_id == 123456789
is_media = event.message.media != None and event.message.document != None
is_sticker = is_media and (event.message.document.mime_type == "image/webp" or event.message.document.mime_type == "application/x-tgsticker")
is_gif = is_media and event.message.document.mime_type == "video/mp4" and event.message.document.size < 1024 * 1024
if is_sticker or is_gif:
await event.delete()
me = client.get_me()
print(me.stringify())
with client:
client.run_until_disconnected()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment