Add files via upload
This commit is contained in:
58
commands/moderation/casier.js
Normal file
58
commands/moderation/casier.js
Normal file
@@ -0,0 +1,58 @@
|
||||
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 d’un 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} n’a 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.');
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user