from telethon import events from config import pmPermitCollecction from config import client @events.register(events.NewMessage(incoming=True , func=lambda e : e.is_private)) async def pmPermit(event): # client = event.client chat = await event.get_chat() user_id = event.message.peer_id.user_id print(user_id) user = pmPermitCollecction.find_one({'user_id':user_id}) if user: if(user['approved']): pass else: if(user['warns'] <2): warn = user['warns'] + 1 await client.send_message(chat , "**Hope!!!\nYou have mentioned why you are here, Because if you send message one more time you will be blocked!!**" , reply_to=event.message) pmPermitCollecction.find_one_and_update({'user_id':user_id} , {'$set':{'warns':warn}}) print(user) else: await client.send_message(chat , "**Blocked!!!\nNow wait for me to come online**" , reply_to=event.message) await client.edit_permissions(chat , send_messages=False) else: try: abt = { "user_id":user_id, "status":1, "warns":1, "approved":0, } pmPermitCollecction.insert_one(abt) except: print("error in db adding") return await client.send_message(chat , "Hey\n\nSeems You are new to me.\n\nPlease state the reason why you are here." , reply_to=event.message) print("search done")