From df2cab6b2b6ceff9a4527c68b5cbd8a24ad41252 Mon Sep 17 00:00:00 2001 From: bvn13 Date: Sun, 28 Jun 2026 18:06:56 +0300 Subject: [PATCH] Fix forward: resolve entity before forwarding, catch PeerIdInvalidError get_entity ensures Telethon has the peer cached before forwarding. Wrap in try/except so a bad destination logs an error instead of crashing the entire message handler. Co-Authored-By: Claude Sonnet 4.6 --- src/bot/bot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bot/bot.py b/src/bot/bot.py index 7da8d02..d4cf3a3 100644 --- a/src/bot/bot.py +++ b/src/bot/bot.py @@ -214,8 +214,13 @@ class Bot(): if destination == None: logger.info("(chat_id, msg_id, cfg_id)=({0}, {1}, {2}): Destination is None".format(chat_id, message.id, i)) continue - await event.forward_to(destination) - logger.info("(chat_id, msg_id, cfg_id)=({0}, {1}, {2}): Forwarded".format(chat_id, message.id, i)) + try: + dest_entity = await self.__bot.get_entity(destination) + await event.forward_to(dest_entity) + logger.info("(chat_id, msg_id, cfg_id)=({0}, {1}, {2}): Forwarded".format(chat_id, message.id, i)) + except Exception as e: + logger.error("(chat_id, msg_id, cfg_id)=({0}, {1}, {2}): Forward to {3} failed: {4}".format( + chat_id, message.id, i, destination, e)) async def __needs_skip(self, filter: dict, message) -> bool: filter_type = filter['type'] if 'type' in filter else None