A discord.js extension for easily creating and managing your Discord Slash Commands. For an in-depth documentation visit the documentation website. Or join the support server to meet the developer. Please note that this package is not associated with discord.js.
npm install @ming-suhi/djs-commando
-
Create a
.env
file in the root directoryCOMMANDS_FOLDER =
-
Create a folder to hold command files. Store the folder path from main as
COMMANDS_FOLDER
.
-
Require
InteractionsHandler
from@ming-suhi/djs-commando
.const { InteractionsHandler } = require('@ming-suhi/djs-commando');
-
Create an instance of
InteractionsHandler
const handler = new InteractionsHandler();
-
Create a file inside the commands folder.
-
Require
Command
.const { Command } = require('@ming-suhi/djs-commando');
-
Create a new class extending
Command
.const ping = new class extends Command { constructor() { super(); // Properties here } }
-
Define class properties inside constructor. Refer to Discord Developer Portal for valid property values.
this.name = "ping"; this.description = "short description";
-
Create execute method which accepts one parameter. The parameter is an instance of
Interaction
class ofdiscord.js
, which is received during interactionCreate event ofdiscord.js
.async execute(interaction) { await interaction.reply("Pong"); }
-
Export created class. If using typescript please also export as shown below.
module.exports = ping;
- Require the desired options.
const { StringField } = require('@ming-suhi/djs-commando');
- Create instance, and extend classes for subcommand group and subcommand.
const message = new StringField('message', 'message to echo', true);
- Pass options to super inside an array. Refer to documentation for the options that can be passed to command, subcommand group and subcommand.
const echo = new class extends Command {
constructor(){
super([message]);
this.name = 'echo';
this.description = 'echo a message';
}
}
- Additional Notes: If you have subcommands, make sure that only the top command is exported.
It is suggested to sync commands on ready
. Synching commands posts and updates commands, as well as deletes commands unexisting in the commands folder. Synching commands bulk updates commands and it is important to note that the recently posted commands cannot be immediately used/seen.
client.on('ready', async() => {
handler.syncCommands(client);
});
This will find the matching command and execute it.
client.on('interactionCreate', async interaction => {
await handler.handleInteraction(interaction);
});
- Create a folder to hold event files. Store the folder path from main as
EVENTS_FOLDER
.
-
Require
EventsHandler
from@ming-suhi/djs-commando
.const { EventsHandler } = require('@ming-suhi/djs-commando');
-
Create an instance of
InteractionsHandler
const handler = new EventsHandler();
-
Create a file inside the events folder. File name must be the same as event name.
-
Create object, set name property as the name of event
-
Set run as the function to run on event
-
Export event
module.exports = { name: 'ready', run() { console.log('Ready!'); } }
It is suggested to register events on ready
.
handler.registerEvents(client);
Context menu commands are not yet available on mobile, so a round-about for this is calling context menu commands through message reply. Just simply reply the command name or alias to the target message or user to call on the corresponding context menu command.
Create a onReply method for the command which accepts one parameter which is an instance of Message
class of discord.js
.
async onReply(message) {
await message.channel.send("Pong");
}
This will find the matching command and execute the onReply method.
client.on('messageCreate', async message => {
await handler.handleMessage(message);
});
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