Вот код, библиотека telethon
async def main():
asyncio.set_event_loop(asyncio.new_event_loop())
client = TelegramClient(session_name, api_id, api_hash)
async with client:
ent_channel_to = await client.get_entity(channel_to)
@client.on(events.NewMessage())
async def handler(event: telethon.events.newmessage.NewMessage.Event):
try:
message_text = event.message.message
msg = event.message
if event.is_channel:
chat_id = event.message.peer_id.channel_id
ent = await client.get_entity(chat_id)
if f"https://t.me/{ent.username}" in titles:
if msg.media:
await client.send_message(ent_channel_to, message_text, file=msg.media)
else:
await client.send_message(ent_channel_to, message_text)
except Exception as e:
print(f"Ошибка: {e}")
await client.run_until_disconnected()