Files
emot_man/commands/emotes/rm.js
2023-11-02 22:54:08 -04:00

29 lines
1.0 KiB
JavaScript

const { SlashCommandBuilder } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("rm")
.setDescription("Removes emotes from the server.")
.addStringOption(option =>
option.setName("emotes")
.setDescription("Emotes to remove.")
.setRequired(true)),
async execute(interaction) {
await interaction.reply("Removing emotes...");
// find every emote in the message and remove them
let emoteList = interaction.options.getString("emotes");
let emoteIdRegex = /<(?<animated>a?):(?<name>\w{0,22})\w*:(?<id>\d+)>/gm;
let replyMessage = "";
for (const match of emoteList.matchAll(emoteIdRegex)) {
let emote = interaction.guild.emojis.cache.find(emoji => emoji.id === match.groups.id);
if (emote) {
await emote.delete();
replyMessage += `Removed ${match[0]}!\n`;
} else {
replyMessage += `Could not find ${match[0]}!\n`;
}
interaction.editReply(replyMessage);
replyMessage = "";
}
},
};