Skip to content

Instantly share code, notes, and snippets.

@capJavert
Last active January 2, 2024 14:06
Show Gist options
  • Save capJavert/d8131d593680290907c435b5b9145144 to your computer and use it in GitHub Desktop.
Save capJavert/d8131d593680290907c435b5b9145144 to your computer and use it in GitHub Desktop.
Discord command handler for creating emoji (short version)
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