[Python] how to track the messages that the subscribers in the telegram channel sent to the...

Discussão em 'Python' iniciado por Stack, Agosto 14, 2025.

  1. Stack

    Stack Membro Participativo

    registered via mobile phone and it's the owner of channel. In telethon, how to track the messages that the subscribers in the telegram channel sent to the admin of the channel via the "direct message" button on the bottom of the channel chat window. Please note I cano track the message that the users sent directly by find my account and send message.

    below is the code. but it can only track the message sent via find my account and send message. it cannot track the messages sent via the "Direct messages" button on the channel.

    ...

    client = TelegramClient('session_name', api_id, api_hash)

    @client.on(events.NewMessage)
    async def handle_dm(event):
    if event.is_private:
    sender = await event.get_sender()
    print(f"\n Message from {sender.username or sender.id}: {event.message.text}")
    await event.reply("Hi! This is the admin. I got your message from the channel.")

    async def main():
    await client.start()
    print("✅ Listening for messages...")
    await client.run_until_disconnected()

    if __name__ == "__main__":
    asyncio.run(main())


    ...

    Continue reading...

Compartilhe esta Página