Command Handler
What Is "Command Handler"?
Command Handler can be used for organizing your bot's commands. Although recommended, its 100% optional.
Setup
In order to use the command handler, you must add the following code to your main file.
bot.manager.load("./commands/")
// You should put this below 'onMessage' event.
Main File Example
(with command handler)
const bdjs = require("d.js-bdscript")
const bot = new bdjs({
token: "token here",
prefix: "prefix"
})
bot.login()
bot.addEvent("onMessage")
bot.manager.load("./commands/")
Using Command Handler
1: Create a folder called "commands".
2: Make a subfolder. (optional)
3: Create the command using the base code below.
module.exports = {
type: "Type",
name: "Name",
code: `Code`
}
Example Code Using Command Handler
module.exports = {
type: "command",
name: "ping",
code: `Pong! $ping ms`
}
Multiple Commands In One File
With command handler, you can create multiple commands inside one file. Example below:
This is only supported in version 5.0.0 and above.
module.exports = [{
type: "command",
name: "hi",
code: `Hello $username`
}, {
name: "ping",
code: `Pong! $ping ms`
}, {
type: "joinCommand",
channel: "39459438494840494",
code: `<@$authorID> just joined the server!`
}] // End the code with this.
This example uses DanBot, but most other services support this feature!
Last updated
Was this helpful?