【问题标题】:How do i make my discord bot shows in chat like "Bot is typing"如何让我的不和谐机器人在聊天中显示,例如“机器人正在打字”
【发布时间】:2020-09-10 05:17:24
【问题描述】:

我是不和谐机器人领域的新手,我有一个想法,就是这样,我想让我的机器人在机器人发送任何消息之前显示“机器人正在输入...”状态。 我只是想让它看起来像真正的打字你知道吗?而且我想这看起来会比立即发送消息更好。

顺便说一句,我正在使用 Discord.py 重写

提前感谢您的帮助!


example for what I want the bot to do.

【问题讨论】:

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


    【解决方案1】:

    使用async with channel.typing()

    如果您不熟悉with 语句,它是一种将代码块包装在语句中的方法,它在代码块的开头和代码块的结尾处执行一些操作。

    例子:

    import asyncio
    
    async def on_message(message):
         if message.startswith('ping'):
              async with message.channel.typing():
                   await asyncio.sleep(1)
                   await message.channel.send('pong')
    

    【讨论】:

      猜你喜欢
      • 2020-12-23
      • 2021-05-10
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 2018-12-17
      • 2019-08-01
      相关资源
      最近更新 更多