Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't handle messages with await client.start(), but can with client.run() #82

Open
3 tasks done
gmankab opened this issue Jul 14, 2024 · 1 comment
Open
3 tasks done

Comments

@gmankab
Copy link

gmankab commented Jul 14, 2024

Checklist

  • I am sure the error is coming from Pyrofork's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install -U git+https://github.com/Mayuri-Chan/pyrofork and reproduced the issue using the latest development version

Description

if i use await client.start() to start client, code can't hadle messages, but if i use client.run(), it works fine

Steps to reproduce

see code example

Code example

this code works just fine, and prints all messages

from pyrogram import Client


client = Client('tg_bot')


@client.on_message()
async def on_msg(_, msg):
    print(f'new msg {msg.id}')


client.run()

this code expected to work same, but it doesn't handle messages and doesn't print anything

from pyrogram import Client, idle
import asyncio


client = Client('tg_bot')


@client.on_message()
async def on_msg(_, msg):
    print(f'new msg {msg.id}')


async def main():
    await client.start()
    await idle()


asyncio.run(main())

Logs

No response

@gmankab
Copy link
Author

gmankab commented Sep 10, 2024

i found a solution

from pyrogram import Client, idle
import asyncio


async def main():
    client = Client('tg_bot')
    @client.on_message()
    async def on_msg(_, msg):
        print(f'new msg {msg.id}')

    await client.start()
    await idle()


asyncio.run(main())

can you please note working code in documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant