AlexzanderFlores / WOKCommands

132 stars 61 forks source link

Handling command errors #194

Open MahdyarEn opened 2 years ago

MahdyarEn commented 2 years ago

It does not work properly and gives errors, Even when I use the exact code of the example:

C:\Users\user\Desktop\bot\commands\ping.ts:20
    if (error === CommandErrors.COMMAND_DISABLED) {
                                ^
TypeError: Cannot read properties of undefined (reading 'COMMAND_DISABLED')
    at error (C:\Users\user\Desktop\bot\commands\ping.ts:20:33)
    at module.exports (C:\Users\user\Desktop\bot\node_modules\wokcommands\dist\command-checks\is-enabled.js:12:9)
    at Client.<anonymous> (C:\Users\user\Desktop\bot\node_modules\wokcommands\dist\CommandHandler.js:119:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[nodemon] app crashed - waiting for file changes before starting...

Here is the code:

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!"',
  testOnly: true,
  slash: "both",
  // 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;

https://docs.wornoffkeys.com/commands/handling-command-errors

mafio900 commented 2 years ago

same issue, besides "error" every property is undefined