我如何让discord.py等待

rab*_*ton 3 python python-3.x discord.py

我怎样才能让discord.py发送一条消息,稍等一下,然后再发送另一条消息?

现在,这是我的命令:

@b.command()
async def message(ctx)
  await ctx.send("First message")
  await ctx.send("Second message after 5 seconds")
Run Code Online (Sandbox Code Playgroud)

小智 7

您可以使用await asyncio.sleep(seconds)。另外,您的代码有一些拼写错误。

@您应该在开头添加,b.command()并且在之后async def message(ctx)添加:。

import asyncio
@b.command()
async def message(ctx):
    await ctx.send('First message')
    await asyncio.sleep(5)
    await ctx.send('Second message after 5 seconds')
Run Code Online (Sandbox Code Playgroud)