When my bot try to resend a group of photos, it splits it into separate messages. If it is a group of photos (in Telegram), I need to resend it wholly, as a group within one message. How to fix it?
from telethon import TelegramClient, events
import asyncio
Id_bot =
Id_Group2 =
Id_Group3 =
Id_Group4 =
Id_Group5 =
api_id = ''
api_hash = ''
client = TelegramClient('none', api_id, api_hash)
@client.on(events.NewMessage)
async def handler(event):
chat = await event.get_chat()
chat_id = event.chat_id
print(chat_id)
# Forward only if the message is not sent in Id_Group1 to avoid an infinite loop
if chat_id not in [Id_Group2, Id_Group3, Id_Group4, Id_Group5]:
if event.media:
if isinstance(event.media, list):
# Multiple media files in a single message
media = []
for file in event.media:
media.append(await client.upload_file(file))
await client.send_file(Id_bot, media[0], caption=event.message.message, file=media[1:])
else:
# Single media file
caption = event.message.message if event.message.message else None
await client.send_file(Id_bot, event.media, caption=caption)
elif event.message.message:
await client.send_message(Id_bot, event.message.message)
client.start()
client.run_until_disconnected()