Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling command errors #194

Open
MahdyarEn opened this issue Dec 6, 2021 · 1 comment
Open

Handling command errors #194

MahdyarEn opened this issue Dec 6, 2021 · 1 comment

Comments

@MahdyarEn
Copy link

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
Copy link

mafio900 commented Feb 1, 2022

same issue, besides "error" every property is undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants