refactor(commands/adminstration): now using the new log system

This commit is contained in:
Raphael 2025-10-26 17:51:24 +01:00 committed by Raphaël
parent 491feedfaf
commit 5db4a7939d
4 changed files with 13 additions and 23 deletions

View file

@ -8,6 +8,7 @@ import {
} from 'discord.js';
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { prisma } from '@lib/prisma';
import { log } from '@lib/log';
import { User as UserPrisma } from '@prisma/client';
export default {
@ -30,13 +31,7 @@ export default {
});
}
catch (err: unknown) {
if (err instanceof Error) {
console.error(`${err.name}: ${err.message}`);
console.error(err.stack);
}
else {
console.error('❌ Unknown error:', err);
}
log.error(err, 'Cannot get user data');
await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral,
@ -81,10 +76,7 @@ export default {
});
}
catch (err: unknown) {
const errorMessage = err instanceof Error ? err.message : String(err);
console.error(
`Cannot delete category or its channels:\n\t${errorMessage}`,
);
log.error(err, 'Cannot delete category or its channels');
await interaction.reply({
content: `${emoji.answer.error} | Failed to delete the category or its channels.`,
flags: MessageFlags.Ephemeral,

View file

@ -15,6 +15,7 @@ import {
} from 'discord.js';
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { Guild, User } from '@prisma/client';
import { log } from '@lib/log';
export default {
data: new SlashCommandBuilder()
@ -62,10 +63,7 @@ export default {
});
}
catch (err: unknown) {
const errorMessage = err instanceof Error ? err.message : String(err);
console.error(
`\t⚠ | Cannot get the database connection!\n\t\t(${errorMessage}).`,
);
log.error(err, 'Cannot get the database connection');
await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral,
@ -367,15 +365,11 @@ export default {
});
}
catch (err: unknown) {
const errorMessage =
err instanceof Error ? err.message : (err as string);
await interaction.reply({
content: `${emoji.answer.error} | Cannot suppress the category's channels`,
flags: MessageFlags.Ephemeral,
});
console.error(
`Cannot suppress the category's channel:\n\t${errorMessage}`,
);
log.error(err, 'Cannot suppress the category\'s channels');
return;
}
await prisma.guild.update({
@ -396,7 +390,7 @@ export default {
break;
}
default:
console.error(`no choice on logs command ${choice}`);
log.error(new Error(`no choice on logs command ${choice}`), 'Invalid logs command choice');
await interaction.reply({
content: `${emoji.answer.error} | Invalid choice`,
flags: MessageFlags.Ephemeral,

View file

@ -1,4 +1,8 @@
import { ButtonBuilder, ActionRowBuilder, SlashCommandBuilder } from '@discordjs/builders';
import {
ButtonBuilder,
ActionRowBuilder,
SlashCommandBuilder,
} from '@discordjs/builders';
import {
StringSelectMenuBuilder,
ButtonStyle,