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;
}
}
}
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;
}
}
}