JaBa/commands/Moderation/warns.js
Jonny_Bro (Nikita) c3dca64be4 prettier
2023-07-05 00:58:06 +05:00

96 lines
2.5 KiB
JavaScript

const { SlashCommandBuilder, PermissionsBitField, EmbedBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Warns extends BaseCommand {
/**
*
* @param {import("../../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("warns")
.setDescription(client.translate("moderation/warns:DESCRIPTION"))
.setDescriptionLocalizations({
uk: client.translate("moderation/warns:DESCRIPTION", null, "uk-UA"),
ru: client.translate("moderation/warns:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
.addUserOption(option =>
option
.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
})
.setRequired(true),
),
aliases: [],
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Object} data
*/
async execute(client, interaction) {
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.user.getUsername(),
}),
iconURL: member.displayAvatarURL(),
})
.setColor(client.config.embed.color)
.setFooter({
text: client.config.embed.footer,
});
if (memberData.sanctions.length === 0) {
embed.setDescription(
interaction.translate("moderation/warns:NO_SANCTIONS", {
member: member.user.getUsername(),
}),
);
return interaction.reply({
embeds: [embed],
});
} else {
memberData.sanctions.forEach(sanction => {
embed.addFields([
{
name: sanction.type,
value: `${interaction.translate("common:MODERATOR")}: <@${sanction.moderator}>\n${interaction.translate("common:REASON")}: ${sanction.reason}`,
inline: true,
},
]);
});
}
interaction.reply({
embeds: [embed],
});
}
}
module.exports = Warns;