I am using telethon 1.36.0
python library to listen for new telegram messages of specific groups.
This is my relevant code:
@client.on(events.NewMessage(chats=channel_names))
async def handler(event):
try:
sender = await event.get_sender()
message = event.message
print(message)
except Exception as e:
print(f"Error: {e}")
where channel_names
is a list of telegram groups usernames I joined to.
If a group is deleted during script execution (while I listen for new messages) and another one of the groups I listen for posts a message, the exception is never triggered and my script crashes due to the following error:
telethon.errors.rpcerrorlist.UsernameNotOccupiedError: The username is not in use by anyone else yet (caused by ResolveUsernameRequest)
The above exception was the direct cause of the following exception:
raise ValueError('No user has "{}" as username'
ValueError: No user has "my_channel_username" as username
Is there a way to prevent that?