Mayuri-Chan / pyrofork

Pyrogram fork with Adjustable web page preview, Quote Reply, Story & Topics Support, Mongodb session storage, and much more. go to https://pyrofork.wulan17.top/ for documentation.
https://pyrofork.wulan17.top
GNU Lesser General Public License v3.0
156 stars 76 forks source link

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

Open gmankab opened 3 months ago

gmankab commented 3 months ago

Checklist

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 commented 1 month ago

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