Home > Mobile >  Capture specific telegram group messages with Telethon python
Capture specific telegram group messages with Telethon python

Time:04-14

Good evening everyone.

I'm trying to get messages from a specific telegram group, using telethon. Can anyone give me a light? I can already get messages from my bot, but how to get messages from other conversations?

Sorry if this post is in the wrong place.

async def main():

me = await client.get_me()

async for message in client.iter_messages('me'):
    print(message.id, message.text)

CodePudding user response:

Take a look at iter_messages docs.

It takes entity as first argument:

The entity from whom to retrieve the message history.

So, replace client.iter_messages('me') with client.iter_messages(chat_id) in your code

CodePudding user response:

paste in an event to run when a message to receive?

async def main():


    async for message in client.iter_messages(id_chat, search="", limit=1):
        msg_Gcrash = (message.sender_id, ':', message.text)
        sinal_Gcrash = msg_Gcrash[2]
        print(sinal_Gcrash)
        if '**Sinal confirmado**' in sinal_Gcrash and len(sinal_Gcrash) > 65:
            sinal_conf = (sinal_Gcrash[69:73])
            sinal_conf = float(sinal_conf)
            print(sinal_conf)
            print("novo sinal")
            #print(sinal_conf)
            #print(sinal_Gcrash)

with client: client.loop.run_until_complete(main())

  • Related