When you react to a message with the "🖼️" emoji it tries to extract the image url from the pasted/uploaded image. If it finds one then it sends a message back to the channel with the url.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const event = context.params.event
// Is this the 🖼️ emoji?
if (event.emoji.name !== "🖼️") return
// Get the original message
const { channel_id, message_id } = event
const message = await lib.discord.channels['@0.2.0'].messages.retrieve({
channel_id, message_id,
});
let image_url = null
// Try to find an uploaded image
if (message.attachments.length) {
const attachment = message.attachments[0]
if (attachment.content_type.startsWith('image/'))
image_url = attachment.url
}
// Try to find an embeded image
else if (message.embeds.length) {
const embed = message.embeds[0]
if (embed.url) image_url = embed.url
}
// Post message with the extracted url
if (image_url)
await lib.discord.channels['@0.2.0'].messages.create({
channel_id, content: `The image url is \`${image_url}\``
});