A discord.js extension for easily structuring and managing your Discord Slash Commands. For an in-depth documentation visit the documentation website. Or join the support server to talk with the developer. Please note that this package is not affiliated with discord.js.
npm install @ming-suhi/djs-commando
Start creating a command by making a file inside a designated folder. File name doesn't need to be command name. Require the needed command class from @ming-suhi/djs-commando
. Command classes include
Command
, Subcommand
, SubcommandGroup
, UserCommand
and MessageCommand
. To create a command class make a new instance of the chosen class and set its properties. Finally for command to be handled by the package, export it with module.exports
. module.exports
only top commands(Command, UserCommand, MessageCommand) not command options such as Subcommand and SubcommandGroup(command options will be discussed below).
const { Command } = require('@ming-suhi/djs-commando');
const command = new class extends Command {
constructor() {
super();
this.name = "ping";
this.description = "get ponged";
}
async execute(interaction) {
interaction.reply("pong");
}
}
module.exports = command;
Require the needed command class from @ming-suhi/djs-commando
. Command options include Subcommand
,
SubcommandGroup
, StringField
, IntegerField
, BooleanField
, UserField
, ChannelField
, RoleField
,
MentionableField
, NumberField
, and AttachmentField
. Create a new instance of the chosen class and pass it inside an array as an argument to it's parent's constructor.
const { StringField } = require('@ming-suhi/djs-commando');
// Creation of field differs from subcommand and subcommand group
// Subcommand and subcommand group are created like Command, UserCommand and MessageCommand
const message = new StringField('message', 'message to echo', true);
const command = new class extends Command {
constructor() {
super([message]); // pass all options inside an array
this.name = "echo";
this.description = "echo a message";
}
async execute(interaction) {
interaction.reply("pong");
}
}
module.exports = command; // only export top command
Before receiving commands, load all commands. First, require InteractionsHandler
from @ming-suhi/djs-commando
. Create new instance of InteractionsHandler
and call loadCommands
method. The method requires one argument which is the path to the commands folder.
const { InteractionsHandler } = require('@ming-suhi/djs-commando');
const handler = new InteractionsHandler();
handler.loadCommands("ABSOLUTE/PATH/TO/COMMANDS/FOLDER");
To receive commands, call handleInteraction
method on interactionCreate
event. Interactions handler
will manage getting the matching command and executing it when interaction is received.
client.on('interactionCreate', async interaction => {
await handler.handleInteraction(interaction);
});
Optionally, you can install @ming-suhi/djsc-cli
to easily manage(post, delete, update) your commands from the command line.
npm install @ming-suhi/djsc-cli
//djsc.config.js
const { mapCommands } = require("@ming-suhi/djs-commando");
module.exports = {
appId: "DISCORD_APP_ID",
botToken: "DISCORD_BOT_TOKEN",
mapCommands: () => mapCommands("ABSOLUTE/PATH/TO/COMMANDS/FOLDER")
}
This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.
For help and questions about using this project, please open a GitHub issue.
Fork the project.
Create a topic branch from master.
Make some commits to improve the project.
Push this branch to your GitHub project.
Open a Pull Request on GitHub.
Discuss, and optionally continue committing.
MIT © 明suhi
Generated using TypeDoc