const { SlashCommandBuilder } = require("discord.js"); const fs = require('fs/promises'); const { EMOTE_DIR } = process.env; module.exports = { data: new SlashCommandBuilder() .setName("dl") .setDescription("Downloads the emote input (local).") .addStringOption(option => option.setName("emotes") .setDescription("The emotes to download.") .setRequired(true) ), async execute(interaction) { await interaction.deferReply(); // this regex matches emotes in the format <:name:id> or let emoteIdRegex = /<(?a?):(?\w{0,22})\w*:(?\d+)>/gm; let replyMessage = ""; const input = interaction.options.getString("emotes"); // remove duplicates from the emote list let emoteList = input.matchAll(emoteIdRegex); emoteList = [...new Set(emoteList)].join(" "); for (const match of emoteList.matchAll(emoteIdRegex)) { const link = "https://cdn.discordapp.com/emojis/" + match.groups.id + ((match.groups.animated == 'a') ? ".gif": ".webp") + "?quality=lossless"; const copyname = match.groups.name + "_FE"; const response = await fetch(link); // save the file await fs.writeFile(`${EMOTE_DIR}${copyname}${(match.groups.animated == 'a') ? ".gif": ".webp"}`, response.body); await interaction.editReply(`Dowloaded ${match[0]}!\n`); replyMessage += `Logged ${match[0]}!\n`; } await interaction.editReply("Done!"); }, };