https://github.com/issadarkthing/commandment
Lightweight discord.js command handling framework
https://github.com/issadarkthing/commandment
discord-js
Last synced: 9 months ago
JSON representation
Lightweight discord.js command handling framework
- Host: GitHub
- URL: https://github.com/issadarkthing/commandment
- Owner: issadarkthing
- License: mit
- Created: 2021-09-06T04:21:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-30T12:57:40.000Z (over 3 years ago)
- Last Synced: 2025-03-02T11:45:02.753Z (9 months ago)
- Topics: discord-js
- Language: HTML
- Homepage: commandment.vercel.app
- Size: 388 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Commandment
Simple [discord.js](https://discord.js.org/#/) 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
```sh
$ npm install @jiman24/commandment
```
## Documentation
You can read about the documentation [here](https://commandment.vercel.app/)
## Example
`index.ts`
```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`
```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`
```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");
}
}
```