1.0.4 • Published 5 years ago
ezcmds v1.0.4
#EZCMDS
const Discord = require("discord.js");
const client = new Discord.Client();
const { Handler } = require("ezcmds");
const handler = new Handler();
handler.register({
client: client,
cmdDirectory: __dirname + "/commands"
});
client.on("message", async message => {
if(!message.guild) return; // return if the message was sent in DMs
const prefix = "!"; // define prefix
if(!message.content.startsWith(prefix)) return; // if the message content doesn't start with our prefix return.
const messageArray = message.content.split(/ +/g); // split the message content at every space
const cmd = messageArray[0].toLowerCase().slice(prefix.length); // get the command that was run
const args = messageArray.slice(1); // define your args
handler.run(cmd, client, message, args); // will run command if it is found. Will also catch errors.
// client.handler.run(cmd, client, message, args); if your event is in a seperate folder you may still access the handler through client.handler
});
client.login("bot token goes here");
exports.run = async (client, message, args) => {
// code goes here.
message.channel.send("Test done!");
}
exports.help = {
name: "test", // required
aliases: ['test1', 'test2'], // optional.
cooldown: 60000 // optional. in milliseconds
}
const Discord = require("discord.js");
const client = new Discord.Client();
const { Handler } = require("ezcmds");
const handler = new Handler();
handler.register({
client: client,
cmdDirectory: __dirname + "/commands",
evtDirectory: __dirname + "/events"
});
client.login("bot token goes here.");
exports.run = async (client, message) => {
if(!message.guild) return;
const prefix = "!";
if(!message.content.startsWith(prefix)) return;
const messageArray = message.content.split(/ +/g);
const cmd = messageArray[0].toLowerCase().slice(prefix.length);
const args = messageArray.slice(1);
client.handler.run(cmd, client, message, args);
}
exports.run = async (client, message) => {
if(!message.guild) return; // return if the message was sent in DMs
const prefix = "!"; // define prefix
if(!message.content.startsWith(prefix)) return; // if the message content doesn't start with our prefix return.
const messageArray = message.content.split(/ +/g); // split the message content at every space
const cmd = messageArray[0].toLowerCase().slice(prefix.length); // get the command that was run
const args = messageArray.slice(1); // define your args
const cool = client.handler.checkCooldown(message.author.id, message.guild.id, cmd); // want to remove cooldowns? Remove this line and the following:
if(cool) return message.channel.send(`You must wait ${cool.hours}h ${cool.minutes}m ${cool.seconds}s before using this command again.`); // remove this line too
const command = client.handler.get(cmd);
if(!command) return;
command.run(client, message, args, "extra", "variables", "now", "work");
client.handler.setCooldown(message.author.id, message.guild.id, cmd); // remove this line too
}
exports.run = async (client, message, args, extra1, extra2, extra3, extra4) => {
message.channel.send(`${extra1} ${extra2} ${extra3} ${extra4}`);
// expected output: "extra variables now work"
}
exports.help = {
name: "test"
}