How to add a function to discord.py event loop?

前端 未结 3 1696
我在风中等你
我在风中等你 2021-02-16 00:01

I am using Python with discord.py. Documentation here

I\'ve got a bot that is running on a Discord server that links the server with a subr

3条回答
  •  一个人的身影
    2021-02-16 00:18

    You can add a function to the bot event loop with Client.loop.create_task(search_submissions()) like this:

    async def search_submissions():
        pass
    
    client = discord.Client()
    
    client.loop.create_task(search_submissions())
    client.run(TOKEN)
    


    Update:

    If you want your function to continue working you can put it in a while loop with some sleeping in between:

    async def search_submissions():
        while(true):
            # do your stuff
            await asyncio.sleep(1)
    

提交回复
热议问题