fix: bot crashing and no logs

This commit is contained in:
zkldi
2023-01-26 18:45:31 +00:00
parent 2f74328aa7
commit c1dbc2ed49
2 changed files with 24 additions and 27 deletions
+20 -25
View File
@@ -26,34 +26,29 @@ export async function handleIsCommand(
throw new Error(`A command was requested that does not exist.`);
}
if (command) {
await interaction.deferReply();
await interaction.deferReply();
logger.verbose(`Running ${command.info.name} interaction.`);
try {
const response = await command.exec(interaction, requestingUser);
logger.verbose(`Running ${command.info.name} interaction.`);
try {
const response = await command.exec(interaction, requestingUser);
const method = interaction.replied ? "followUp" : "reply";
if (response instanceof MessageEmbed) {
await interaction[method]({ embeds: [response] });
} else if (response !== null) {
await interaction[method](response);
} else {
await interaction.reply({
content: "Done!",
ephemeral: true,
});
}
} catch (err) {
logger.error(`An error occured while executing a command.`, { command, err });
const method = interaction.replied ? "followUp" : "reply";
interaction[method](
"An error has occured while executing this command. This has been reported."
);
// eslint-disable-next-line cadence/no-instanceof
if (response instanceof MessageEmbed) {
await interaction.editReply({ embeds: [response] });
} else if (response !== null) {
await interaction.editReply(response);
} else {
await interaction.reply({
content: "Done!",
ephemeral: true,
});
}
} catch (err) {
logger.error(`An error occured while executing a command.`, { command, err });
void interaction.editReply(
"An error has occured while executing this command. This has been reported."
);
}
} catch (e) {
logger.error("Failed to handle isCommand interaction", { error: e });
+4 -2
View File
@@ -5,7 +5,7 @@ import type { LoggerLayers } from "../data/data";
import type { MeiLogger } from "mei-logger";
import type { SeqLogLevel } from "seq-logging";
const logger = CreateLogger(`tachi-bot`, undefined, []);
const transports: Array<any> = [];
if (BotConfig.LOGGER?.SEQ_API_KEY && ProcessEnv.seqUrl) {
// Turns winston log levels into seq format.
@@ -23,7 +23,7 @@ if (BotConfig.LOGGER?.SEQ_API_KEY && ProcessEnv.seqUrl) {
debug: "Debug",
};
logger.transports.push(
transports.push(
new SeqTransport({
apiKey: BotConfig.LOGGER.SEQ_API_KEY,
serverUrl: ProcessEnv.seqUrl,
@@ -38,6 +38,8 @@ if (BotConfig.LOGGER?.SEQ_API_KEY && ProcessEnv.seqUrl) {
);
}
const logger = CreateLogger(`tachi-bot`, undefined, transports);
export default logger;
export function CreateLayeredLogger(layerName: LoggerLayers) {