我在python中制造了一个不和谐的bot,其中一些命令让bot输入了一堆废话。但是每次我都要有一个完整的异步,asyncio.sleep。
@client.command()
async def talk(ctx):
s(3)
async with ctx.typing():
await asyncio.sleep(2)
await ctx.send("Hello")
s(2)
async with ctx.typing():
await asyncio.sleep(4)
await ctx.send("My name is bob.")
s(5)
async with ctx.typing():
await asyncio.sleep(3)
await ctx.send("But first..")
s(2)
async with ctx.typing():
await asyncio.sleep(10)
await ctx.send("Tell me more about astronomy.")
s(2)
async with ctx.typing():
await asyncio.sleep(5)
await ctx.send("And about oranges.")
s(2)
async with ctx.typing():
await asyncio.sleep(2)
await ctx.send("Please")我想加入一个独立的方法,我可以调用。就像这样:
def speak(ctx, msg, prewait=0, typewait=3):
sleep(prewait)
async with ctx.typing():
await asyncio.sleep(typewait)
await ctx.send(msg)
return None但这不起作用,因为我不能使用关键字异步,并在异步方法之外等待。有一个干净的解决办法吗?
发布于 2021-12-17 16:53:53
将async添加到def speak(ctx, msg, prewait=0, typewait=3)中。
https://stackoverflow.com/questions/70343182
复制相似问题