This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
generated from ijsKoud/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ErrorHandler as IgloErrorHandler, InteractionHandlerError } from "@snowcrystals/iglo"; | ||
import { bold, underline } from "colorette"; | ||
import { DiscordAPIError, type Interaction } from "discord.js"; | ||
|
||
export class ErrorHandler extends IgloErrorHandler { | ||
/** | ||
* Logs the error and makes sure the user is aware of the situation. This function is overridable for customisability. | ||
* @param error The error that was emitted | ||
* @param interaction The interaction from the user that used the bot | ||
*/ | ||
public override async handleError(error: Error, interaction?: Interaction): Promise<void> { | ||
if (error instanceof InteractionHandlerError) { | ||
let fatal = false; | ||
if (["InvalidDirectory", "noConstructorOptions"].includes(error.type)) fatal = true; | ||
|
||
const message = `${bold(underline(`InteractionHandlerError(${error.type})`))}: ${error.message}`; | ||
this.client.logger[fatal ? "fatal" : "error"](message); | ||
} else if (error instanceof DiscordAPIError && interaction && !this.isSilencedError(interaction.channelId ?? "", interaction.guildId, error)) | ||
this.client.logger.error(`${bold(underline(`DiscordAPIError(${error.name})`))}: ${error.message}`); | ||
else this.client.logger.error(`${bold(underline(`Error(${error.name})`))}: ${error.message} --- raw=`, error); | ||
|
||
if (interaction && interaction.isRepliable()) | ||
await interaction | ||
.followUp({ | ||
content: | ||
"Welcome to our corner of errors, a place you shouldn't come to too often. It is probably not your fault though, something on our side brought you here. Stay safe out there, if this happens again make sure to contact the support team." | ||
}) | ||
.catch(() => void 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters