WOKCommands
Search…
Handling command errors
WOKCommands sends an error message by default, however you might want to customize this more and perhaps send an embed instead of a normal message. You can listen to command errors to achieve this.
Here is a list of all command errors you can listen for:
  • EXCEPTION
  • COOLDOWN
  • INVALID ARGUMENTS
  • MISSING PERMISSIONS
  • MISSING ROLES
  • COMMAND DISABLED
Each one will provide various pieces of information depending on what the error is. For example "MISSING ROLES" will provide a list of missing roles. "INVALID ARGUMENTS" will provide the arguments the user used in the command.
To listen to command errors you can pass an error function in your command object like so:
JavaScript
TypeScript
ping.js
const { MessageEmbed } = require('discord.js')
module.exports = {
// Best practice for the built-in help menu
category: 'Testing',
description: 'Replies with "Pong!"',
// Invoked when the command is actually ran
callback: ({ message }) => {
message.reply({
content: 'Pong!'
})
},
// Invoked when there is an error when running this command
error: ({ error, command, message, info }) => {
// "error" holds one of the strings mentioned in the above list
if (error === 'COMMAND DISABLED') {
// For example we can now create and send a custom embed
const embed = new MessageEmbed()
.setTitle('Command disabled')
.setColor(0xff0000)
message.reply({
embeds: [embed]
})
}
},
}
ping.ts
import { MessageEmbed } from 'discord.js'
import { ICommand, CommandErrors } from 'wokcommands'
export default {
// Best practice for the built-in help menu
category: 'Testing',
description: 'Replies with "Pong!"',
// Invoked when the command is actually ran
callback: ({ message }) => {
message.reply({
content: 'Pong!'
})
},
// Invoked when there is an error when running this command
error: ({ error, command, message, info }) => {
// "error" holds one of the strings mentioned in the above list
if (error === CommandErrors.COMMAND_DISABLED) {
// For example we can now create and send a custom embed
const embed = new MessageEmbed()
.setTitle('Command disabled')
.setColor(0xff0000)
message.reply({
embeds: [embed]
})
}
},
} as ICommand
Copy link