2
目前我有这样的:命令超时| Discord.js
const Discord = require("discord.js");
const PREFIX = ",";
const token = "my token";
var bot = new Discord.Client();
bot.on('ready',() => {
bot.on('message', message => {
if (!message.content.startsWith(PREFIX)) return; //if not command ignore message
var args = message.content.substring(PREFIX.length).split(" "); //splits commands so each word = pos in array
switch (args[0].toLowerCase()) { //not case-sensitive anymore
case "hello":
message.channel.send("hello");
break;
//rest of the commands
我想限制命令“你好”的用法。我希望每次用户输入“hello”时都会有10秒的超时时间。如果用户在冷却前输入命令,它会发送一条消息,说明谁最后使用了该命令,以及冷却时间还剩多长时间。
这就是我想要的结果看起来像:
User1: ,hello
Bot: hello
(After 1 second)
User2: ,hello
Bot: User1 has already used this command, please wait another 9 seconds to use it again
(After 9 seconds)
User 2: ,hello
Bot: hello
所有帮助表示赞赏。 谢谢,
是的,'lastHelloCommandDate'应该初始化为'0'。如果它是'undefined'(如上所述),则结果为'new Date() - undefined',这会导致'NaN'(不会超过任何数字)。 –