How to handle client getting disconnected?

I am using telethon to write a script.

async def main():     client = TelegramClient('session',api_id,api_hash)     await client.connect()     await client.start()     @client.on(events.NewMessage())     async def handler(event):         print(event.messsage.text)     await client.run_untill_disconnected() asyncio.run(main()) 

The code works fine for normal use. It fetches updates and prints them. But, I am in search of an special event. Say, while the client is running and the user terminates this session from the telegram app forcefully, then my script stops working which is very obvious. Now, The problem is that when session is terminated I want to handle that event(or may be error) in realtime in my code, so that it starts doing some other task. How do I do it..?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.