[英]How do i make my discord bot shows in chat like “Bot is typing”
I'm new to the field of discord bots, I had an idea and it's that, I want to make my bot show "bot is typing..." status before the bot send any messages.我是 discord 机器人领域的新手,我有一个想法,就是这样,我想让我的机器人在机器人发送任何消息之前显示“机器人正在输入......”状态。 I simply want it to looks like real typing you know?
我只是想让它看起来像真正的打字你知道吗? And I guess that will look better than just sending the messages immediately.
而且我想这看起来比立即发送消息要好。
BTW, I'm using Discord.py Rewrite顺便说一句,我正在使用 Discord.py 重写
Thanks for your help in advance!提前感谢您的帮助!
Use async with channel.typing()
将
async with channel.typing()
使用
If you are unfamiliar with the with
statement, it is a way of wrapping a codeblock in a statement, which does something at the start of the code block and the end of the codeblock.如果您不熟悉
with
语句,它是一种将代码块包装在语句中的方式,它在代码块的开头和代码块的结尾处执行一些操作。
Example:例子:
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.