[Python] Python Userbot doesn't respond to message

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have got userbot, which responds to certian messages in group topics. But it doesn't respond, how to fix it?

    from decouple import config
    from telethon.sync import TelegramClient
    from telethon.events.newmessage import NewMessage
    import re

    api_id = config('API_ID')
    api_hash = config('API_HASH')
    phone = config('PHONE')
    login = config('LOGIN')
    MESSAGE_TO_MATCH = r'^Hello'

    client = TelegramClient("some_session", api_id, api_hash)

    @client.on(NewMessage())
    async def handle_new_message(event):
    print("new message")
    if re.match(MESSAGE_TO_MATCH, event.message.text):
    response = f"Message got!"

    await client.send_message(event.chat_id, response, reply_to=event.id)

    await client.disconnect()

    if __name__ == "__main__":
    print("start listening")

    client.start(phone=phone)


    client.run_until_disconnected()


    Method handle_new_message doesn't even got called

    Continue reading...

Compartilhe esta Página