const { SlashCommandBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('add') .setDescription("Add an external emoji in the server.") .addSubcommand(subcommand => subcommand .setName('emoji') .setDescription("Add an external emoji in the server.") .addStringOption(option => option .setName('emoji') .setDescription("The emoji.") .setRequired(true)) .addStringOption(option => option .setName('name') .setDescription("The emoji name."))), async execute(interaction) { if (!interaction.guild.members.me.permissions.has(PermissionsBitField.Flags.ManageGuildExpressions)) return await interaction.reply({ content: "I don't have permission to execute this command!", ephemeral: true }); await interaction.deferReply({ ephemeral: true }); let emoji = interaction.options.getString('emoji')?.trim(); const parseEmoji = (text) => { if (text.includes('%')) text = decodeURIComponent(text); else if (!text.includes(':')) return { animated: false, name: text, id: undefined }; let match = text.match(/?/); return match && { animated: Boolean(match[1]), name: match[2], id: match[3] }; }; try { let customEmoji = parseEmoji(emoji); let emojiName = interaction.options.getString('name') || customEmoji.name; let format = 'png'; if (customEmoji.animated) format = 'gif'; else if (emoji.startsWith('<') && emoji.endsWith('>')) emoji = `https://cdn.discordapp.com/emojis/${customEmoji.id}.${format}?quality=lossless`; else if (!emoji.startsWith('https') || !emoji.startsWith('http') || !customEmoji.id) return await interaction.editReply({ content: "Please provide a valid **discord** emoji!" }); await interaction.guild.emojis.create({ attachment: emoji, name: emojiName.replace(/\s+/g, '_') }).then(async (e) => { await interaction.editReply({ content: `Successfully added **${e}** to the server!` }); }); } catch (error) { await interaction.editReply({ content: "Something went wrong! This might be due to:\n\n1: Emoji slots being full.\n2: An invalid (or a default) emoji may be provided.\n3: Emoji name with unknown characters may be provided (only alphabets, numbers & underscores are allowed)." }); } } }, };