[英]Discord.js: How can i make my bot typing for some seconds?
我想在我的 Discord 机器人响应命令之前在我的 Discord 机器人中放置一个小的“冷却时间”,你知道我必须添加什么才能实现吗?
You can simply mark the bot as typing, then use setTimeout(() => { ... }, 2e3)
to eg wait 2 seconds before executing the code in the arrow function.您可以简单地将机器人标记为正在输入,然后使用setTimeout(() => { ... }, 2e3)
来等待 2 秒,然后再执行箭头函数中的代码。
Normally this is used for if a command can take a long time to execute, eg if it's querying/fetching a database, doing heavy computations, ... and usually not manually.通常这用于命令可能需要很长时间才能执行的情况,例如,如果它正在查询/获取数据库,进行大量计算,......并且通常不是手动的。 After all, most users want bots to respond quickly instead of wasting a few seconds for a typing indicator.毕竟,大多数用户希望机器人能够快速响应,而不是浪费几秒钟的时间来输入指示符。
sleep(second * 1000)
效率更高
Something as simply as this should work像这样简单的东西应该可以工作
client.on("message", (message) => {
if(message.content == "!ping"){
message.channel.startTyping();
sleep(2000) // Wait two seconds.
message.channel.send("pong!");
message.channel.stopTyping()
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.