from telethon import TelegramClient, events
import asyncio
api_id = api_id
api_hash = 'api_hash'
bot_token = 'bot_token '
channel_id = -1002097695773
my_channel_id = -1005556005808
client = TelegramClient('anon', api_id, api_hash)
async def is_message_already_forwarded(message):
if message.forward:
async for msg in client.iter_messages(my_channel_id, limit=100):
if msg.forward and msg.forward.channel_post == message.forward.channel_post:
return True
return False
@client.on(events.NewMessage(chats=channel_id))
async def my_event_handler(event):
chat = await event.get_chat()
if not await is_message_already_forwarded(event.message):
await asyncio.sleep(2) # Wait for 24 hours
# Forward the entire message as a whole, including text and all media
await event.message.forward_to(my_channel_id)
with client:
client.run_until_disconnected()
I have the code:
It redirects the content from one channel to another channel if the text or photo is working fine, but if the photo album has 5 photos+text then it copies 4 photos separately and the last photo with text. Please tell me how to rewrite the code so that the entire album is copied in one message.
I have the code:
It redirects the content from one channel to another channel if the text or photo is working fine, but if the photo album has 5 photos+text then it copies 4 photos separately and the last photo with text. Please tell me how to rewrite the code so that the entire album is copied in one message.
user24629167 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.