ErrorHandler - Paultje52/SupaBotBase GitHub Wiki
You need to activate the ErrorHandler before you can use it. Activating is really simple: Just add bot.activateErrorHandler()
before you start your bot.
Note: If you want to use a database to store your errors, you need to activate the ErrorHandler after you activated your database. Don't want to use a database for your errors? Activate the error handler before you activate your database.
The ErrorHandler catches two types of errors.
- Errors from commands. You'll get the error, the command and the original message that caused the error. All the error information is sent in the console, the log channel (if active) and stored in the database (if active).
unhandledRejection
enuncaughtException
. You'll only get the error and the date that it occurred (a timestamp). The error is sent in the log channel (if active) and stored in the database (if active)
bot.activateErrorHandler();
Message when an error occurred when running a command
Log channel
After activating the ErorHandler, you can set a log channel using bot.errorHandler.setLogChannel("CHANNEL_ID")
. All the errors will be sent with all the information available in this channel. There is even a system to get a invite to the server where the error took place!
When using a database, the error log messages get automatically deleted when you use ErrorHandler#removeError()
. When deleting an error log message, the error will also be deleted from the database!
bot.errorHandler.setLogChannel("CHANNEL_ID");
Error caused by a command
Error caused by something else
Database
When you have a database active, you can get your errors (a list and each error) with the command/message data. The functions here are all only available when you have a database active!
The keys in the database are as follows: error-<ID>
. An error ID is always 8 characters long.
Note: You can only fetch the invite in the log channel when you have a database enabled!
getErrorList
This function returns an array with all the error id's.
let errors = bot.errorHandler.getErrorList();
getError
This function get's an error and all the information with it. There are two types of errors.
- Errors caused by commands
- Other errors
When calling this function, you'll get the message and command object when the errortype is 1 and the errortype and time when the error is 2.
let error = await bot.errorHandler.getError("ID");
if (error.message) {
// Error caused by command
// Available properties: message, error and cmd (Only the command properties)
} else {
// Error caused by something else
// Available properties: error, type and time (Timestamp)
}
removeError
When removing an error, the log message for the error also get's removed. When deleting the log message, the error is automatically deleted from the database.
let success = await bot.errorHandler.removeError("ID");