-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodlogs.js
61 lines (52 loc) · 1.9 KB
/
modlogs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const {
Client,
Interaction,
EmbedBuilder,
} = require("discord.js");
const fs = require("fs");
const path = require("path");
const logsFilePath = path.join(__dirname, "../modlogs.json");
module.exports = {
/**
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
try {
const targetUser = interaction.options.getUser("user");
if (!targetUser) {
return await interaction.reply({ content: "Please provide a valid user.", ephemeral: true });
}
let modLogs = {};
if (fs.existsSync(logsFilePath)) {
const data = fs.readFileSync(logsFilePath);
modLogs = JSON.parse(data);
}
const userLogs = modLogs[targetUser.id] || [];
if (userLogs.length === 0) {
return await interaction.reply({ content: `No moderation history found for **${targetUser.tag}**.`, ephemeral: true });
}
const embed = new EmbedBuilder()
.setColor("#4ea554")
.setTitle(`Moderation Logs for ${targetUser.tag}`)
.setThumbnail(targetUser.displayAvatarURL({ dynamic: true }))
.setDescription(userLogs.map(log => `**[${log.type}]** - \`${log.reason}\` (By: <@${log.moderator}>) - <t:${log.timestamp}:F>`).join("\n") || "No logs found.")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL({ dynamic: true }) })
.setTimestamp();
await interaction.reply({ embeds: [embed] });
} catch (error) {
console.error("Error fetching mod logs:", error);
await interaction.reply({ content: "An error occurred while retrieving moderation logs.", ephemeral: true });
}
},
name: "modlogs",
description: "View moderation history of a user.",
options: [
{
name: "user",
description: "The user whose mod logs you want to view.",
type: 6,
required: true,
},
],
};