Telegram Bot not Connecting to API

Viewed 103

I have been using the Telegram API for a while to listen for messages in specific channels on one account. The code below works ok. I tried to use the same code to create another listener for a different account but it doesn't work. I don't get any errors.

When I look on the official Telegram app the listener is not listed under "Devices" which suggests it is not connecting to the API correctly.

Before testing I created a new API ID and hash at my.telegram.org. I've triple checked that the ID, hash and channel ID are all correct.

Can anyone think what the issue might be?

Thanks

from telethon import TelegramClient, events, sync

api_id = 'xxxxxxxxxx'
api_hash = 'xxxxxxxxxxxxxxxxxx'
client = TelegramClient('anon', api_id, api_hash)
chat_id = xxxxxxxx

@client.on(events.NewMessage(chats=chat_id))
async def newMessageListener(event):
    new_message = event.message.message
    chat_id = event.chat_id
    print(chat_id)
    print(new_message)
    print()

    screenshot = "new_image.jpg"

    if event.message.photo:
        await event.download_media(screenshot)
        print("New image received")
0 Answers
Related