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".

image

2: Make a subfolder. (optional)

image

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`
}

image

Multiple Commands In One File

With command handler, you can create multiple commands inside one file. Example below:

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.

Last updated

Was this helpful?