I am trying to start a TelegramClient
session inside a function.
there are no errors, but the decorator for events.NewMessage
doesn't seem to act...
here is the code I use:
async def runClient(sessionName):
client = getClientBySessionName(sessionName) # this is constructed with TelegramClient from telethon.sync
await client.connect()
me = await client.get_me()
print(me.first_name)
await client.disconnect()
if not me:
return
await client.start()
@client.on(events.NewMessage)
async def nmh(event):
await newMessageHandler(event, client)
async def newMessageHandler(event, client):
print(event.raw_text)
and to make sure that I have created the TelegramClient right, I have tested other methods on it, and it works fine
when new messages accrue, nothing is logged
Did you try something like this?
@client.on(events.NewMessage(chats=user_input_channel))
async def newMessageListener(event):
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.