Search code examples
pythontelegrampyrogram

How to wait for messages from user pyrogram


example of my code, but when the bot switches to another command, this remains Is there an example of how this can be done?

async def test(client, message):
    user_id = message.chat.id
    await bot.send_message(user_id, "write code:")
    @bot.on_message(filters.private & filters.user(user_id))
    async def get_code(client, message):
        code = message.text```

Solution

  • firstly install the pyromod module with pip.

    Then reframe the code like this:

    from pyromod import listen
    from pyrogram import Client, filters
    
    app = Client(...)
    
    @app.on_message(filters.private)
    async def snd_something(client, message):
        asking = await c.ask(chat_id, 'send something..')
    

    With the pyromod library all you have to do is from pyromod import listen. You can access the text sent by the user by using asking.text. You can get more details on this Here