Chnage Logs
What's New?
- It's completely changed from v1.
- Fixed the cooldown not working bug.
- Before there were no variables for logging settings.
You can find them here
- Fixed a bug in help command :)
Configuration
To install the command handler, install npm
and then in a terminal run this command where you want your bot npm i @silent-coder/discord-cmd-handler
. After it create your main file (index.js) and add this into it :
const {
cmdHandler,
logger
} = require("@silent-coder/discord-cmd-handler");
const Discord = require("discord.js")
const client = new Discord.Client();
client.login("TOKEN HERE");
client.on("ready", () => {
logger.info(`Logged in as ${client.user.tag} Successfully..!!`)
cmdHandler(client,{
logs: {
consoleLogEnabled: true,
consoleLogMessage: "{user.tag} ( {user.id} ) ran a command: {command} in {guild.name} ( {channel.name} )",
cmdLogEnabled: false,
cmdLogChannel: "ChannelID HERE",
cmdLogMessage: "{user.tag} ( {user.id} ) ran a command: {command} in {guild.name} ( {channel.name} )"
},
cooldownMSG: "Calm down, {user.tag}, You still have {time} before you can run the command again.",
EnableCommmandonEdit: true,
mentionPrefix: true,
prefix: "?",
owners: ["YOUR DISCORD ID", "YOUR TRUSTED FRIEND Discord ID"],
path: __dirname + "/commands",
events_path: __dirname + "/events",
logCommands: true
});
});
Usage
After adding the above code to index.js you need todo the following steps to make Command Handler work:-
- Make a Directory ( Folder ) in the same Directory where your main file ( index.js ) is located. Name the folder
commands
. - Open the Directory that you made.
- Make a new Directory ( Folder ) inside the
commands
Directory. This Folder will be the name of the Category. You can name it anything. - Open the Directory that you made.
- Now make a
module.json
and put this inside it.
{
"hide": false
}
- Save the file.
- Now You can make a file
help.js
and paste this Code. - Save the file.
- You can make as many as many commands as you like using this Template.
- Feel free to DM me on Discord
☠ Be Intelligent ☠#2385
if having any issues & Enjoy!
Templates
Commands
const Discord = require("discord.js")
exports.run = async (client, message, args, logger) => {
try {
} catch (error) {
logger.error(error);
}
}
exports.help = {
name: "Command-Name",
description: "Command-description",
usage: "Command-usage",
example: "Command-example"
}
exports.conf = {
aliases: [],
cooldown: 5
}
Help Command
This will auto make help command when adding new commands.
const Discord = require("discord.js");
const {
settingFunction
} = require("@silent-coder/discord-cmd-handler")
exports.run = async (client, message, args) => {
let prefix = settingFunction().prefix;
if (!args[0]) {
let module = client.helps.array();
if (!settingFunction().owners.includes(message.author.id)) module = client.helps.array().filter(x => !x.hide);
const embed = new Discord.MessageEmbed()
.setColor(0x1d1d1d)
.setTimestamp(new Date())
.setDescription(`Type \`${prefix}help [command]\` to get more specific information about a command.`)
.setTitle("My Bot")
.setAuthor("Bot made by Me.!!")
.setFooter(
"Requested by " + message.author.username,
message.author.displayAvatarURL({
format: "png",
dynamic: true
})
)
let i = 0;
for (const mod of module) {
embed.addField(mod.name, mod.cmds.map(x => `\`${x}\``).join(" | "));
i++
};
return message.channel.send(embed);
} else {
let cmd = args[0];
if (client.commands.has(cmd) || client.commands.get(client.aliases.get(cmd))) {
let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));
let name = command.help.name;
let desc = command.help.description;
let cooldown = command.conf.cooldown + " second(s)";
let aliases = command.conf.aliases.join(", ") ? command.conf.aliases.join(", ") : "No aliases provided.";
let usage = command.help.usage ? command.help.usage : "No usage provided.";
let example = command.help.example ? command.help.example : "No example provided.";
let embed = new Discord.MessageEmbed()
.setColor(0x7289DA)
.setTitle(name)
.setDescription(desc)
.setThumbnail(client.user.displayAvatarURL())
.setFooter("[] optional, <> required. Don't includes these things while typing a command.")
.addField("Cooldown", cooldown)
.addField("Aliases", aliases, true)
.addField("Usage", usage, true)
.addField("Example", example, true)
return message.channel.send(embed);
} else {
return message.channel.send({
embed: {
color: "RED",
description: "Unknown command."
}
});
}
}
}
exports.help = {
name: "help",
description: "Show a command list.",
usage: "help [command]",
example: "/help verify"
}
exports.conf = {
aliases: ["?"],
cooldown: 5
}
Variables and Settings Help.