Shows how to use the 'Attachment' slash command option. This will send the image back to the channel as an embed.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let attachmentid = context.params.event.data.options[0]?.value;
let attachmentData =
context.params.event.data?.resolved?.attachments?.[attachmentid];
if (attachmentData) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Here is your slash command image!`,
embed: {
image: {
url: attachmentData.url,
},
},
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Slash command uploaded image not found`,
});
}