Search code examples
telegram-bottelethontelegram-api

How to get and send all messages from the channel to channel?


I have a code that can copy a message from one channel to another channel, but this code works only for "NewMessages", how to make this code to send all messages from the channel to another channel?

from telethon import TelegramClient, events
import asyncio

api_id = 
api_hash = ''

my_channel_id = -1001247324182
channels = [-100129537617]

client = TelegramClient('myGrab', api_id, api_hash)
print("GRAB - Started")

@client.on(events.NewMessage(chats=channels))
async def my_event_handler(event):
    if event.message:
        await client.send_message(my_channel_id, event.message)
 
 
client.start()
client.run_until_disconnected()

So, it is possible to do this code to send all messages from the channel? Maybe, another library?


Solution

  • You can iter_messages and forward it to new channel