Create commands
Explains how to set up commands

Directory structure

This is an example directory structure
1
Commands - // Directory containing commands
2
example.js
3
index.js
Copied!

Example code in index.js

Initializing the Object
1
// Regular Discord.js Stuff
2
const Discord = require("discord.js");
3
const client = new Discord.Client({ shardCount: 1 });
4
5
// Now we initialize the Object
6
const { Commands } = require("djs-command-control");
7
const commands = new Commands(
8
client,
9
"Commands", // The `Commands` Directory as specified above
10
{
11
prefix: process.env.PREFIX,
12
prefixOnMention: true,
13
}
14
);
Copied!

Code appearing in Commands/example.js

Example code setup for the file inside the example command
1
// First importing the class
2
const { Command } = require("djs-command-control");
3
4
// Instatiate the object
5
const command = new Command();
6
7
// Setting up all the variables
8
command.name = "example";
9
command.description = "An Example Command";
10
command.invokes = ["example", "ex"]; // Command can both be invoked with 'ex' and 'example'
11
command.usage = "{{Example Parameter}}";
12
command.permission = ["MANAGE_GUILD"]; // Command can only be executed by users holding the MANAGE_GUILD permission
13
command.category = "general"; // The command should appear in the 'general' category
14
command.execute = async (message, options) => {
15
// Do some example stuff
16
};
17
command.omitHelp = false; // This command should appear in Command
18
19
// Export the command
20
module.exports = command;
21
22
Copied!
Last modified 4mo ago