简体   繁体   中英

How can I call an async function inside a command in discord python?

For example:

@client.command()
async def hello(ctx):
   await ctx.send('hello')
   facts()

async def facts(ctx):
   await ctx.send('facts')

I tried this but it usually gives an error like - RunTimeWarning: 'coroutine _____ was never awaited'

The answer to this question is to add an await. before your async function.

@client.command()
async def hello(ctx):
   await ctx.send('hello')
   await facts(ctx)

async def facts(ctx):
   await ctx.send('facts')

And there you'd be able to call your async function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM