1.4.0 • Published 2 years ago
@jiman24/commandment v1.4.0
Commandment
Simple discord.js command framework.
Why
Because I find myself repeating over and over again doing command handling. This library will certainly reduce the development time with powerful command handling for the bot.
Features
- one command per file
- multiple instance blocking i.e. prevent user from running the same command while the other command is still running
- lightweight
- easy to use
- command throttling
Installing
$ npm install @jiman24/commandment
Documentation
You can read about the documentation here
Example
index.ts
import { Client } from "discord.js";
import { CommandManager } from "../index";
import path from "path";
const COMMAND_PREFIX = "!";
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const commandManager = new CommandManager(COMMAND_PREFIX);
commandManager.verbose = true;
commandManager.registerCommands(path.resolve(__dirname, "./commands"));
commandManager.registerCommandNotFoundHandler((msg, cmdName) => {
msg.channel.send(`Cannot find command "${cmdName}"`);
})
commandManager.registerCommandOnThrottleHandler((msg, cmd, timeLeft) => {
const time = (timeLeft / 1000).toFixed(2);
msg.channel.send(`You cannot run ${cmd.name} command after ${time} s`);
})
client.on("ready", () => console.log(client.user?.username, "is ready!"))
client.on("messageCreate", msg => commandManager.handleMessage(msg));
client.login(process.env.BOT_TOKEN);
commands/Ping.ts
import { Message } from "discord.js";
import { Command } from "../../index";
export default class extends Command {
name = "ping";
aliases = ["p"];
throttle = 10 * 1000; // 10 seconds
exec(msg: Message, args: string[]) {
msg.channel.send("pong");
}
}
commands/Wait.ts
import { Message } from "discord.js";
import { Command } from "../../index";
export default class extends Command {
name = "wait";
block = true;
private sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
})
}
async exec(msg: Message, args: string[]) {
msg.channel.sendTyping();
const [ms] = args;
await this.sleep(parseInt(ms))
msg.channel.send("done");
}
}
1.4.0
2 years ago
1.2.0
2 years ago
1.1.0
2 years ago
1.0.0
2 years ago
1.3.3
2 years ago
1.3.2
2 years ago
1.3.1
2 years ago
1.3.0
2 years ago
0.8.0
2 years ago
0.7.0
2 years ago
0.6.2
2 years ago
0.5.0
2 years ago
0.4.1
2 years ago
0.6.1
2 years ago
0.4.3
2 years ago
0.6.0
2 years ago
0.5.1
2 years ago
0.4.2
2 years ago
0.3.13
2 years ago
0.3.12
2 years ago
0.3.11
2 years ago
0.4.0
2 years ago
0.3.9
3 years ago
0.3.10
3 years ago
0.3.8
3 years ago
0.2.8
3 years ago
0.2.7
3 years ago
0.2.6
3 years ago
0.2.5
3 years ago
0.1.5
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago