JaBa/commands/Moderation/warns.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-08-03 21:13:22 +05:00
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Warns extends BaseCommand {
/**
*
* @param {import("../../base/JaBa")} client
*/
2022-08-03 21:13:22 +05:00
constructor(client) {
super({
2022-08-03 21:13:22 +05:00
command: new SlashCommandBuilder()
.setName("warns")
2022-08-03 21:13:22 +05:00
.setDescription(client.translate("moderation/warns:DESCRIPTION"))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers && PermissionFlagsBits.ManageMessages)
.addUserOption(option => option.setName("user")
.setDescription(client.translate("common:USER"))
.setRequired(true)),
aliases: [],
dirname: __dirname,
guildOnly: true
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
2022-08-09 23:48:33 +05:00
* @param {Object} data
*/
async execute(client, interaction) {
2022-08-03 21:13:22 +05:00
const member = interaction.options.getMember("user");
if (member.user.bot) return interaction.error("misc:BOT_USER");
const memberData = await client.findOrCreateMember({
id: member.id,
guildId: interaction.guildId
});
const embed = new EmbedBuilder()
.setAuthor({
name: interaction.translate("moderation/warns:SANCTIONS_OF", {
member: member.nickname || member.user.username
}),
iconURL: member.displayAvatarURL({
extension: "png",
size: 512
})
})
.setColor(client.config.embed.color)
.setFooter({
text: client.config.embed.footer
});
2022-08-03 21:13:22 +05:00
if (memberData.sanctions.length === 0) {
embed.setDescription(interaction.translate("moderation/warns:NO_SANCTIONS", {
member: member.nickname || member.user.username
}));
return interaction.reply({
embeds: [embed]
});
} else {
2022-08-03 21:13:22 +05:00
memberData.sanctions.forEach(sanction => {
embed.addFields([
{
2022-08-03 21:13:22 +05:00
name: sanction.type + " | #" + sanction.case,
value: `${interaction.translate("common:MODERATOR")}: <@${sanction.moderator}>\n${interaction.translate("common:REASON")}: ${sanction.reason}`,
inline: true
}
]);
});
}
interaction.reply({
embeds: [embed]
});
}
}
module.exports = Warns;