import { ApplyOptions } from "@sapphire/decorators";
import { Events, Listener, type MessageCommandErrorPayload, UserError } from "@sapphire/framework";
import { EmbedBuilder } from "discord.js";
//import { captureException } from '@sentry/node';
import * as Sentry from "@sentry/node";
import functions from "../../../utils/functions";
import config from "../../../config";
@ApplyOptions<Listener.Options>({
event: Events.MessageCommandError,
})
export class MessageCommandErrorListener extends Listener {
public override async run(error: UserError, { message }: MessageCommandErrorPayload) {
console.log("hi")
if (!error.name) return await functions.error(message, error.toString());
if (error.toString().includes("No subcommand was matched with the provided arguments."))
return await functions.error(message, "Invalid subcommand.");
if (typeof error === "string") {
await functions.error(message, error);
return;
}
if (typeof error !== "string") {
const sentry = Sentry.captureException(error);
const errorID = await functions.rng(12);
const errorEmbed = new EmbedBuilder();
errorEmbed.setAuthor({
name: `Command Error`,
iconURL: this.container.client.user?.displayAvatarURL(),
});
errorEmbed.setDescription(`${error}`);
errorEmbed.addFields([
{ name: "Error ID", value: `> ${errorID.toString()}`, inline: true },
{
name: "Command",
value: `> ${arguments[1].command!.name || "Unknown"}`,
inline: true,
},
{
name: "Sentry Report",
value: "[Click Here](https://sentry.io/" + sentry + ")",
},
]);
this.container.logger.error(
`Encountered the following error while running ${
arguments[1].command.name
}: ${errorID.toString()} - Sentry report: https://sentry.io/${sentry}`,
);
if (message.channel || message)
await message.channel.send({
content: `Failed to execute this command. Report this error ID (\`${errorID}\`) to a developer.`,
});
await functions.sendWebhook(config.webhooks.errors.id, config.webhooks.errors.token, { embeds: [errorEmbed] });
return;
}
}
}
#Any reason as to why this event wouldn't be firing?
1 messages · Page 1 of 1 (latest)
The first question would be are your message commands working at all? And if so, are you actually throwing an error in them? Keep in mind that preconditions are a different event.
They are, I'm throwing the exceptions with a basic throw 'error goes here' call
if (result.isErr())
throw 'You do not have sufficent permissions to view this command.';
its not just the error events
its the success event too that i know of
the denied event works though
and all work for slash commands i think
What are the names of all the files? Names have to be unique per piece type, even across folders. So no 2 files called error for example. Or if you do want that, set the name property in applyoptions
Names have to be unique because we store it in a Map which requires unique keys (same for Objects for that matter)
Thank you for marking this question as solved!
Learn more