How do I auto forward messages instantly from a channel to another channel? I created an example but doesn’t work.
This is my example:
`from telethon import TelegramClient, events
api_id = 99999999
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
@client.on(events.NewMessage)
async def my_event_handler(event):
chat = await event.get_chat()
if chat.id == 'Horse Racing Daily Tips Premium':
await client.forward_messages('Greyhounds Daily Tips Premium', event.message)
with client:
client.run_until_disconnected()`
I tried to send from my source channel "Horse Racing Daily Tips Premium" to my destination channel ‘Greyhounds Daily Tips Premium’; I am new of Python and Telegram bot so I am not sure I did the correct way.
I already launched the bot from my prompt command line, but doesn’t work
2
Answers
1-
chat.id
is integer, you can’t compare it to a string2- using string chat title to fetch or match is not reliable all the time if more than one chat has the same name, so prefer chat identifiers if it’s private channel or usernames if it’s public channel, but if it works for your case keep it.
you can use event.forward_to()
like this:
or use client.forward_messages()
like this: