const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js'); const Infraction = require('../../models/infraction'); module.exports = { data: new SlashCommandBuilder() .setName('unwarn') .setDescription("Remove a warning from a user") .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers) .setDMPermission(false) .addUserOption(option => option .setName('user') .setDescription('User you wish to unwarn') .setRequired(true) ) .addStringOption(option => option .setName('infraction_id') .setDescription('The ID of the warning you want to remove') .setRequired(true) ), async execute(interaction) { await interaction.deferReply({ ephemeral: true }); const { options, guild, member } = interaction; const target = options.getMember('user'); const infractionId = options.getString('infraction_id'); // Allowed roles const allowedRoles = ['HR Admin', 'Tulajdonos', 'Mod', 'Admin']; // Check if the command user has one of the allowed roles const memberRoles = member.roles.cache.map(role => role.name); const hasPermission = allowedRoles.some(role => memberRoles.includes(role)); if (!hasPermission) { return interaction.editReply({ content: "Ehhez nincs engedélyed.", ephemeral: true }); } // Check if the target user has a higher or equal role, or if both are in the allowed roles const targetRoles = target.roles.cache.map(role => role.name); const targetHasHigherRole = target.roles.highest.position >= member.roles.highest.position; const bothHaveAllowedRole = allowedRoles.some(role => memberRoles.includes(role)) && allowedRoles.some(role => targetRoles.includes(role)); if (targetHasHigherRole || bothHaveAllowedRole) { return interaction.editReply({ content: "Ezt a felhasználót nem figyelmeztetheted.", ephemeral: true }); } const guildId = guild.id; const targetId = target.id; let embed = new EmbedBuilder(); const infraction = await Infraction.findOne({ where: { id: infractionId, userId: targetId, guildId: guildId, type: 'Warn' } }); if (!infraction) { return interaction.editReply({ content: "Figyelmeztetés nem található ezzel az azonosítóval.", ephemeral: true }); } await infraction.destroy().then(() => { embed .setColor(0x00FF00) // GREEN in hexadecimal .setAuthor({ name: target.user.tag, iconURL: target.user.displayAvatarURL() }) .setTitle('Infraction Removed') .setDescription(`Removed by ${member.user.tag}`) .addFields( { name: 'ID', value: "`" + infractionId + "`", inline: true, }, { name: 'Type', value: "`Warn`", inline: true, }, { name: 'Guild', value: "`" + guild.name + "`", inline: false, } ); }).catch(err => { console.error(err); return interaction.editReply({ content: "Hiba történt a figyelmeztetés eltávolítása közben.", ephemeral: true }); }); await interaction.editReply({ embeds: [embed] }); } };