【发布时间】:2018-12-17 13:27:29
【问题描述】:
所以如果我有一个像这样的长命令:
@bot.command(pass_context=True)
async def longCommand(ctx):
#typing status
sleep(10)
bot.say("Done!")
不幸的是,在文档或此处未找到任何内容。
【问题讨论】:
标签: python python-3.x discord discord.py
所以如果我有一个像这样的长命令:
@bot.command(pass_context=True)
async def longCommand(ctx):
#typing status
sleep(10)
bot.say("Done!")
不幸的是,在文档或此处未找到任何内容。
【问题讨论】:
标签: python python-3.x discord discord.py
@bot.command()
async def type(ctx):
await ctx.channel.trigger_typing()
await asyncio.sleep(5)
await ctx.send("Done!")
这对我有用! 我正在使用 Discord.py(不重写)
【讨论】:
编辑:较新版本的不和谐要求您使用新语法:
@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。
【讨论】:
如果你使用重写分支,那么所有Messageables 都有一个typing 上下文管理器允许你无限期地输入,还有一个trigger_typing 协程显示输入消息几秒钟。
@bot.command()
async def longCommand(ctx):
async with ctx.typing():
await sleep(10)
await ctx.send("Done!")
【讨论】: