const { SlashCommandBuilder, PermissionsBitField, EmbedBuilder } = require("discord.js"); const warningSchema = require("../../models/warnSchema"); const colors = require('../../colors.json') module.exports = { data: new SlashCommandBuilder() .setName('clear-warn') .setDescription('Clears the mentioned members warnings') .addUserOption(option => option.setName("user").setDescription("The user you want to clear the warnings of").setRequired(true)), async execute(interaction) { const permissions = 'Administrator' if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { const modembed = new EmbedBuilder() .setDescription('❌ You **do not** have permissions to run this command! ❌') .setTimestamp() .setFooter({ text: `Permissions needed: ${permissions}`}) .setImage('https://cdn.discordapp.com/attachments/847184918878224447/1114162959183249488/Stop_hand.svg.png') .setColor('Red') return await interaction.reply({ embeds: [modembed] }); } const { options, guildId, user } = interaction; const target = options.getUser("user"); const embed = new EmbedBuilder() warningSchema.findOne({ GuildID: guildId, UserID: target.id, UserTag: target.tag }, async (err, data) => { if (err) throw err; if (data) { await warningSchema.findOneAndDelete({ GuildID: guildId, UserID: target.id, UserTag: target.tag}) embed.setColor(colors.mod) .setDescription(`✅ ${target.tag}'s warnings have been cleared!`) .setTimestamp() interaction.reply({ embeds: [embed] }); } else { const nowarns = new EmbedBuilder() .setDescription(`\`❗${target.tag} has no warnings to be cleared!\``) .setColor(colors.cant) interaction.reply({ embeds: [nowarns] }); } }); } }