im trying to create a cooldown for my status command, because they spam a lot on the server the status command and i want a cooldown like 5m and that send a message like, βyou need to wait 5m more to use this command im really newbie to javascript, so if anyone can help me
Here its my entire command:
JavaScript
βx
56
56
1
const Discord = require("discord.js");
2
const yaml = require("js-yaml");
3
β
4
const supportbot = yaml.load(
5
fs.readFileSync("./Configs/supportbot.yml", "utf8")
6
);
7
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
8
β
9
const Command = require("../Structures/Command.js");
10
const { timeStamp } = require("console");
11
var request = require('request');
12
β
13
const Gamedig = require('gamedig');
14
β
15
let state = null;
16
β
17
β
18
setInterval(() => {
19
β
20
β
21
Gamedig.query({
22
type: 'minecraft',
23
host: 'mc.latinplay.net',
24
port: '25565'
25
})
26
.then((updatedState) => {
27
state = updatedState;
28
players = state.players.length;
29
}).catch((error) => {
30
console.log("Server is offline");
31
});
32
}, 6000);
33
β
34
module.exports = new Command({
35
name: cmdconfig.EstadoCommand,
36
description: cmdconfig.EstadoCommandDesc,
37
β
38
β
39
async run(interaction) {
40
β
41
const LatinEstado = new Discord.MessageEmbed()
42
.setColor('RANDOM')
43
.setTitle('ππππ’π§ππ₯ππ² ππππ°π¨π«π€ **Estado del Servidor**')
44
.setURL("https://store.latinplay.net/")
45
.addField('**Jugadores en linea:**', `${players || "0"}`)
46
.addField('**Estado Actual:**', "**En Lineaπ**", true)
47
.setThumbnail('https://media0.giphy.com/media/5RQ6coK6GVXGfPPq69/giphy.gif?cid=790b76115867f0dba05d9cf2aceb80efed5b0e494387e3b2&rid=giphy.gif&ct=g')
48
.setFooter({ text: 'LatinBot | Version 1.0 ', iconURL: 'https://cdn.discordapp.com/attachments/953043417234026547/988805760458821642/Diseno_sin_titulo.png' });
49
interaction.reply({
50
embeds: [LatinEstado],
51
});
52
53
}
54
},
55
);```
56
β
Advertisement
Answer
Just store last command run time in a map.
JavaScript
1
2
1
const cooldown={}; // Add this
2
β
β¦
JavaScript
1
27
27
1
module.exports = new Command({
2
name: cmdconfig.EstadoCommand,
3
description: cmdconfig.EstadoCommandDesc,
4
async run(interaction) {
5
//
6
if (interaction.user.id in cooldown && cooldown[interaction.user.id] - Date.now() > 0) // in cool down
7
return interaction.reply("In cooldown! Please wait 5 min!");
8
cooldown[interaction.user.id] = Date.now() + 300000; // 5 min in ms.
9
//
10
const LatinEstado = new Discord.MessageEmbed()
11
.setColor('RANDOM')
12
.setTitle('ππππ’π§ππ₯ππ² ππππ°π¨π«π€ **Estado del Servidor**')
13
.setURL("https://store.latinplay.net/")
14
.addField('**Jugadores en linea:**', `${players || "0"}`)
15
.addField('**Estado Actual:**', "**En Lineaπ**", true)
16
.setThumbnail('https://media0.giphy.com/media/5RQ6coK6GVXGfPPq69/giphy.gif?cid=790b76115867f0dba05d9cf2aceb80efed5b0e494387e3b2&rid=giphy.gif&ct=g')
17
.setFooter({
18
text: 'LatinBot | Version 1.0 ',
19
iconURL: 'https://cdn.discordapp.com/attachments/953043417234026547/988805760458821642/Diseno_sin_titulo.png'
20
});
21
interaction.reply({
22
embeds: [LatinEstado],
23
});
24
β
25
}
26
});
27
β