简体   繁体   English

Discord.js:我怎样才能让我的机器人打字几秒钟?

[英]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.

相关问题 如何让我的机器人每 10 秒更改一次状态? (在线,空闲,免打扰)Discord.js - How can I make my bot change status every 10 seconds? (Online, Idle, DND) Discord.js 在 discord.js 中闲置 15 秒后,如何让我的机器人与语音断开连接 - how can I make my bot disconnect from voice after 15 seconds being idle in discord.js 如何在网站上制作 discord.js 机器人统计信息? - How I can make discord.js bot statistics on website? 如何为我的 Discord.js 机器人创建奇偶命令? - How can I make an even-odd command for my Discord.js bot? 如何为我的 discord.js 机器人发出禁令命令? - How can I make a ban command for my discord.js bot? 如何发出重置命令来重新启动我的 discord.js 机器人? - How can i make a reset command to restart my discord.js bot? Discord.js机器人程序需要帮助-如何使我的机器人每6小时自动执行一项任务而不发送命令? - Discord.js bot help needed - how can I make my bot auto do a task every 6 hours without sending it a command? 如何使我的 discord 机器人具有自定义状态 (discord.js) - How do I make my discord bot have a custom status (discord.js) 我想让我的 discord.js 机器人不可见 - I'm looking to make my discord.js bot invisible 我怎样才能实现!leaveguild<guildid> 命令(离开指定的公会)进入我的 Discord (discord.js) 机器人?</guildid> - How can I implement a !leaveguild <guildID> command (that leaves the specified guild) into my Discord (discord.js) bot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM