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 <noreply@anthropic.com>
This commit is contained in:
bvn13 2026-06-28 18:06:56 +03:00
parent 6c2c07430a
commit df2cab6b2b

View File

@ -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