Discods.js
Description: Thinking about a command which sends how many times this command is used. More like a counting.
I know you will suggest “store value in database and then increment it”.
But i wanna see an example please…how how. You can call me dumb😔
Whenever a command is executed, add it to the database.
There are varieties of database out there - like Endb;
You can try this…
Put This Code When Command Is Ran
Note: I am using Enmap, you can use any DB.
const Enmap = require('enmap');
const client.counter = new Enmap({name:"command-counter"});
//Under Ready Events
client.counter.ensure(message.guild.id+"_counters", { ping: 0, help: 0 });//put all commands here
//Put This Below Code Under Each Command File.
try {
client.counter.inc(message.guild.id+"_counters", this.name);
}
catch(error) {
console.log(error)
}
Notes:
- Do not copy code directly without understanding.
- This is generalized way. This will differ from each projects to projects.
- Will throw error if ran in DMs.
-
this.name
refers to command name. Put Manually otherwise - enmap.inc increases number count.
I’d definitely recommend Endb.
As I said, you can use any DB
. I just gave an example.