如何使不协调机器人显示Bot正在键入...状态? [英] How can I make Discord bots display the "Bot is typing ..." status?
本文介绍了如何使不协调机器人显示Bot正在键入...状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以如果我有一个很长的命令,比如:
@bot.command(pass_context=True)
async def longCommand(ctx):
#typing status
sleep(10)
bot.say("Done!")
遗憾的是,在文档中或此处未找到任何内容。
推荐答案
编辑:较新版本的Discord要求您使用新语法:
@bot.command()
async def mycommand(ctx):
async with ctx.typing():
# do expensive stuff here
await asyncio.sleep(10)
await ctx.send('done!')
旧版本使用此命令:
@bot.command(pass_context=True)
async def longCommand(ctx):
await bot.send_typing(ctx.channel)
await asyncio.sleep(10)
await bot.say("Done!")
记住对协程的每个异步调用使用await
。
这篇关于如何使不协调机器人显示Bot正在键入...状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文