Error Handler
Reading time:1 min read
The CommandErrorHandler is responsible for handling errors thrown by middlewares and commands.
It's inside the CommandExecutor object, and will be used by it.
When to override
| ✅ Override if you want to... | ❌ Don't override if you want to... |
|---|---|
| Resolve consumers with a different logic. | Add new consumers or a fallback one. The object already supports these operations. |
Overriding
Creation
Create a custom error handler by either:
- Extending
BasicErrorHandler<AnyExecutableCommand, CommandExecutionArgs>(recommended, less work). - Implementing
CommandErrorHandler.
import { , type , type } from '@nyx-discord/djs';
class extends <, > {}Registration
Create it and set it to the CommandExecutor, then set the executor on the CommandManager.
import { } from '@nyx-discord/djs';
class extends <, > {}
const = .({
: {
: .(),
},
});
.().();The create() method instantiates your custom error handler, not the default one.
Using the Bot's logger
The default error handler will use console.error as a fallback consumer. If you want to change it to the bot's logger, instantiate it this way:
import { } from '@nyx-discord/djs';
import type { , } from '@nyx-discord/djs';
const = .<, >(
(, , [, ]) => .(),
);Edit on GitHub
Last updated on
