1.1.1 • Published 6 years ago
easycommands v1.1.1
EASYCOMMANDS
const Discord = require('discord.js');
const client = new Discord.Client();
const { EasyCommands } = require("easycommands");
const handler = new EasyCommands();
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("your bot token goes here.");
const { Command } = require("easycommands");
class Help extends Command {
constructor(){
super({
name: "help", // required
aliases: ['help1', 'help2'], // optional
usage: "help", // optional
description: "Show all commands.", // optional
category: "General", // optional. Defaults to 'General'
cooldown: 60000 // optional. Defaults to 0. Time is in milliseconds.
});
}
async run(client, message, args) {
message.reply("Hello!");
}
}
module.exports = Help;
const Discord = require('discord.js');
const client = new Discord.Client();
const { EasyCommands } = require("easycommands");
const handler = new EasyCommands();
handler.register({
client: client,
cmdDirectory: __dirname + "/commands",
evtDirectory: __dirname + "/events"
});
client.login("your bot token goes here.");
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
client.handler.run(cmd, client, message, args); // will run command if it is found. Will also catch errors.
}
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
}
const { Command } = require("easycommands");
class Help extends Command {
constructor(){
super({
name: "help", // required
aliases: ['help1', 'help2'], // optional
usage: "help", // optional
description: "Show all commands.", // optional
category: "General", // optional. Defaults to 'General'
cooldown: 5000 // optional. Defaults to 0. Time is in milliseconds.
});
}
async run(client, message, args, extra1, extra2, extra3, extra4) {
message.reply(`${extra1}, ${extra2}, ${extra3}, ${extra4}`);
// expected output: @author, extra, variables, now, work
}
}
module.exports = Help;