Initializing the Object
This example includes how to initialize the Commands Object
Basic initialization
// Regular Discord.js Stuff
const Discord = require("discord.js");
const client = new Discord.Client({ shardCount: 1 });
// Now we initialize the Object
const { Commands } = require("djs-command-control");
const commands = new Commands(
client, // Passing our Discord Client
"src/commands", // Lets pretens our commands are located in src/commands
{ // Finally passing the CommandOptions Object
prefix: process.env.PREFIX, // We have our prefix stored in the env variables
prefixOnMention: true, // Yes, we want to return the prefix if someone mentions the bot
}
);
Our bot has a customizable prefix feature
// Start by initializing the discord.js client and importing djs-commands-control
// Let's say we have a function that fetches the prefix from our database
// The arguments has to be message and options, as described in the CustomizablePrefix Type
function fetchPrefix(message, options) {
return options.database.fetchPrefix(message.id); // This has to return a string
}
// Let's create a CustomizablePrefix Option
const customizablePrefix = {
callback: fetchPrefix, // The above function to run
options: { database } // The function requires the database object
}
// Now we initialize the Object
const commands = new Commands(
client, // Passing our Discord Client
"src/commands", // Lets pretens our commands are located in src/commands
{ // Finally passing the CommandOptions Object
prefix: process.env.PREFIX, // We have our prefix stored in the env variables
prefixOnMention: true, // Yes, we want to return the prefix if someone mentions the bot
customizablePrefix, // Finally, give it to the contructor
}
);
We do not want to have general as the default category
// Start by initializing the discord.js client and importing djs-commands-contro
// Let's create a defaultCategory Option
const defaultCategory = {
name: "something-else",
title: "Something Else"
}
// Now we initialize the Object
const commands = new Commands(
client, // Passing our Discord Client
"src/commands", // Lets pretens our commands are located in src/commands
{ // Finally passing the CommandOptions Object
prefix: process.env.PREFIX, // We have our prefix stored in the env variables
prefixOnMention: true, // Yes, we want to return the prefix if someone mentions the bot
defaultCategory , // Finally, give it to the contructor
}
);
We wish to include a help command that is part of our new default category
// Start by initializing the discord.js client and importing djs-commands-contro
// Let's create a helpOptions Object
const helpOptions = {
include: true, // yes we want it included
omitFromHelp: true, // no need to show the help commands inside of the help command, helpception.
category: "something-else" // The name of the category we want the help command to appear in
}
// Now we initialize the Object
const commands = new Commands(
client, // Passing our Discord Client
"src/commands", // Lets pretens our commands are located in src/commands
{ // Finally passing the CommandOptions Object
prefix: process.env.PREFIX, // We have our prefix stored in the env variables
prefixOnMention: true, // Yes, we want to return the prefix if someone mentions the bot
help: helpOptions, // Finally, give it to the contructor
}
);
We don't want people spamming the bot, so let's add a ratelimiter
// Start by initializing the discord.js client and importing djs-commands-contro
// Let's create a rateLimiterOptions Object
const rateLimiterOptions = {
enabled: true, // yes, we want to use the ratelimiter
amount: 2, // Lets say we want to allow 2 commands in a timeframe
interval: 6000 // Lets make said timeframe 6 seconds
}
// Now we have a ratelimiter that will allow 2 commands every 6 seconds
// Now we initialize the Object
const commands = new Commands(
client, // Passing our Discord Client
"src/commands", // Lets pretens our commands are located in src/commands
{ // Finally passing the CommandOptions Object
prefix: process.env.PREFIX, // We have our prefix stored in the env variables
prefixOnMention: true, // Yes, we want to return the prefix if someone mentions the bot
rateLimiter: rateLimiterOptions , // Finally, give it to the contructor
}
);
Last updated