【问题标题】:How can I make Discord bots display the "Bot is typing ..." status?如何让 Discord 机器人显示“机器人正在输入……”状态?
【发布时间】: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


    【解决方案1】:
    @bot.command()
    async def type(ctx):
        await ctx.channel.trigger_typing()
        await asyncio.sleep(5)
        await ctx.send("Done!")
    

    这对我有用! 我正在使用 Discord.py(不重写)

    【讨论】:

      【解决方案2】:

      编辑:较新版本的不和谐要求您使用新语法:

      @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

      【讨论】:

        【解决方案3】:

        如果你使用重写分支,那么所有Messageables 都有一个typing 上下文管理器允许你无限期地输入,还有一个trigger_typing 协程显示输入消息几秒钟。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-07
          • 2021-09-09
          • 2020-07-29
          • 2021-07-29
          • 2021-04-03
          • 1970-01-01
          • 2019-11-06
          • 2021-07-20
          相关资源
          最近更新 更多