Setup Validations Path

Validations are functions that are executed before executing the command itself. Every time a command is triggered on Discord, your code will first execute all the initial checks (validations) that you have written. They act like middlewares do for APIs.

To setup validations, you must provide the validationsPath property when creating a new instance of CommandHandler.

Validations can only work in the presence of commandsPath.

index.js
const { Client, IntentsBitField } = require('discord.js');
const { CommandHandler } = require('djs-commander');
const path = require('path');

const client = new Client({
  intents: [IntentsBitField.Flags.Guilds], // Your bot's intents
});

new CommandHandler({
  client, // Discord.js client object | Required by default
  commandspath: path.join(__dirname, 'commands'), // Your commands directory (required for validations)
  validationsPath: path.join(__dirname, 'validations'), // Your validations directory (requires commandsPath)
});

client.login('YOUR_TOKEN_HERE');

Different Validations Folder

As with both the commands and events path, your validationPath can lead to a folder with any name anywhere. For example, if I have my validations saved inside a folder called bot-validations, I would define validationPath like this.

validationsPath: path.join(__dirname, 'bot-validations')

Last updated