Files
Femboy-Croissant-Bot/commands/moderation/casier.js
2025-08-30 18:05:01 +02:00

59 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const db = require('../../functions/database/db.js'); // instance mysql2/promise
module.exports = {
category: 'moderation',
data: new SlashCommandBuilder()
.setName('casier')
.setDescription('Voir toutes les sanctions dun membre.')
.addUserOption(option =>
option.setName('membre')
.setDescription('Le membre dont tu veux voir le casier')
.setRequired(true)),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
const member = interaction.options.getUser('membre');
try {
const [rows] = await db.query(
'SELECT * FROM logs WHERE userId = ? ORDER BY timestamp DESC',
[member.id]
);
if (!rows.length) return interaction.editReply(`${member.tag} na aucune sanction.`);
const embed = new EmbedBuilder()
.setTitle(`Casier de ${member.tag}`)
.setColor('Orange')
.setTimestamp();
rows.forEach((row, index) => {
const date = new Date(row.timestamp).toLocaleString();
const actionCapitalized = row.action.charAt(0).toUpperCase() + row.action.slice(1); // Ban/Unban
// Récupère le nom du serveur via l'ID si présent
const guildName = row.guildId
? interaction.client.guilds.cache.get(row.guildId)?.name || 'Unknown Server'
: 'Unknown Server';
embed.addFields({
name: `#${index + 1} - ${actionCapitalized}`,
value: `**Modérateur:** <@${row.modId}> (${row.modTag || 'N/A'})\n` +
`**Raison:** ${row.reason || 'N/A'}\n` +
`**Serveur:** ${guildName}\n` +
`**Date:** ${date}`,
inline: false
});
});
await interaction.editReply({ embeds: [embed] });
} catch (err) {
console.error(err);
await interaction.editReply('❌ Une erreur est survenue lors de la récupération du casier.');
}
},
};