diff --git a/paper/client.py b/paper/client.py index 07d365c..32ca1d1 100644 --- a/paper/client.py +++ b/paper/client.py @@ -23,7 +23,8 @@ from telethon.errors.rpcerrorlist import ( UsersTooMuchError, UserChannelsTooMuchError, UserIsBlockedError, - YouBlockedUserError + YouBlockedUserError, + UsernameInvalidError, ) class PaperClient(TelegramClient): @@ -93,11 +94,13 @@ class PaperClient(TelegramClient): return await super().get_participants(group, *args, **kwargs) async def __cast_to_entity(self, entity: Entity | EntityLike) -> Entity: - if not isinstance(entity, Entity): - if hasattr(entity, "username"): - entity = await self.get_entity(entity.username) - else: - entity = await self.get_entity(entity) - - return entity # type: ignore + try: + if not isinstance(entity, Entity): + if hasattr(entity, "username"): + entity = await self.get_entity(entity.username) + else: + entity = await self.get_entity(entity) + return entity # type: ignore + except UsernameInvalidError as e: + raise IgnoreException(e)