-
-
Save capJavert/d8131d593680290907c435b5b9145144 to your computer and use it in GitHub Desktop.
Discord command handler for creating emoji (short version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const command = async interaction => { | |
// extract options from slash command | |
const emojiName = interaction.options.get('name', true).value | |
const { attachment } = interaction.options.get('image', true) | |
const fit = interaction.options.get('fit', false)?.value || 'cover' | |
// construct params for API endpoint | |
const emojiImageParams = new URLSearchParams() | |
emojiImageParams.append('image', attachment.url) | |
emojiImageParams.append('fit', fit) | |
// since fetch is async we show a loading indicator to user | |
await interaction.deferReply({ ephemeral: true, fetchReply: true }) | |
// my API endpoint | |
const emojiImage = await fetch(`/discord/emoji?${emojiImageParams.toString()}`) | |
.then(res => res.arrayBuffer()) | |
const emoji = await interaction.guild.emojis.create({ | |
name: emojiName, | |
attachment: Buffer.from(emojiImage) | |
}) | |
await interaction.editReply({ content: `Done! You can use new emoji with :${emoji.name}:` }) | |
} | |
export default command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment