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'(不會超過任何數字)。 –