Validation setup

There are two types of validations:

Runtime validations:

  • Ran against a command when it is used
  • Should return a true or false for if the command should be ran
  • You must provide any error messages if need be
  • Arguments:
    • command: Command
    • usage: CommandUsage
    • prefix: string

Syntax validations:

  • Ran against every command when your bot starts up
  • Should throw an error if the syntax for your command is wrong
  • Arguments:
    • command: Command

Here is an example of setting up your validations in your main file:

typescript
import path from 'node:path'
import { Client, IntentsBitField, Partials } from 'discord.js'
import NYXB from '@nyxb/commands'
require('dotenv/config')

const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.DirectMessages,
    IntentsBitField.Flags.MessageContent,
  ],
  partials: [Partials.Channel],
})

client.on('ready', () => {
  console.log('The bot is ready')

  new NYXB({
    client,
    mongoUri: process.env.MONGO_URI || '',
    commandsDir: path.join(__dirname, 'commands'),
    validations: {
    // Where your runtime validation folder is
      runtime: path.join(__dirname, 'validations', 'runtime'),
      // Where your syntax validation folder is
      syntax: path.join(__dirname, 'validations', 'syntax'),
    },
  })
})

client.login(process.env.TOKEN)
javascript
const path = require('node:path')
const { Client, IntentsBitField, Partials } = require('discord.js')
const NYXB = require('@nyxb/commands')
require('dotenv/config')

const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.DirectMessages,
    IntentsBitField.Flags.MessageContent,
  ],
  partials: [Partials.Channel],
})

client.on('ready', () => {
  console.log('The bot is ready')

  new NYXB({
    client,
    mongoUri: process.env.MONGO_URI || '',
    commandsDir: path.join(__dirname, 'commands'),
    validations: {
    // Where your runtime validation folder is
      runtime: path.join(__dirname, 'validations', 'runtime'),
      // Where your syntax validation folder is
      syntax: path.join(__dirname, 'validations', 'syntax'),
    },
  })
})

client.login(process.env.TOKEN)