'Telethon events.NewMessage(channelId) to read all message from a channel?

Im trying to create a python script that can read all messages in a chat channel. I found this code, however, this will only read the message that I write myself or are directed at me. How do I change this code so it can read all the messages in the channel?

from telethon import TelegramClient, events

api_id = 242...
api_hash = '8a06ca620417c9964a058e0dc...'
bot_token = '1474729480:AAEhUPmVX_m...'
channelId = -36744...

client = TelegramClient('bot', api_id, api_hash).start(bot_token=bot_token)

client.start()

@client.on(events.NewMessage(chats = [channelId]))
async def my_event_handler(event):
    text = event.text
    print(text)

client.run_until_disconnected()



Solution 1:[1]

You may use iter_messages to get previous messages

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Simon Yong