python - 如何让 Discord 机器人显示 "Bot is typing ..."状态?

标签 python python-3.x discord discord.py

所以如果我有一个像这样的长命令:

@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

关于python - 如何让 Discord 机器人显示 "Bot is typing ..."状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51252714/

相关文章:

python-3.x - 导入整个文件夹的python文件

python - Unicode 字符串适用于 python2,但不适用于 python3

python - 将逗号分隔的项目拆分为 scrapy 中的列表

Python (matplotlib) 小于或等于文本中的符号

python - Pip3 不适用于 OS X

javascript - (Mongo/Mongoose) 如何处理等待多个查询结果

python - 如何解决 -discord.http : We are being rate limited. 回复 429

javascript - Discord 机器人嵌入变量返回为未定义

python - 从一个数据的结构中找到外推并将其应用于另一个数据

python - 如何使用 boolean 值退出 'for' 循环?