如何使机器人程序显示“机器人正在键入…”状态?

2024-06-25 23:37:58 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,如果我有这么长的命令:

@bot.command(pass_context=True)
async def longCommand(ctx):
   #typing status
   sleep(10)
   bot.say("Done!")

很遗憾,在文档或这里没有找到任何东西。在


Tags: 命令truetypingasyncdefbotstatuscontext
2条回答
@bot.command(pass_context=True)
async def longCommand(ctx):
   await bot.send_typing(ctx.channel)
   await asyncio.sleep(10)
   await bot.say("Done!")

记住在每次对协程的异步调用中使用await。在

如果您使用重写分支,那么所有Messageable都有一个^{}上下文管理器,它允许您无限期地输入,还有一个^{}协同程序,它显示键入消息几秒钟。在

@bot.command()
async def longCommand(ctx):
   async with ctx.typing():
        await sleep(10)
   await ctx.send("Done!")

相关问题 更多 >