When someone sends a file to a channel in your Discord server, this snippet fetches the file, downloads it from Discord, and sends it back to the channel. Meant as an example for how to retrieve files from messages sent to Discord.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let fileMetadata = context.params.event.attachments[0]
if (!fileMetadata) {
return;
}
let fileResponse = await lib.http.request['@1.1.6']({
method: 'GET',
url: fileMetadata.url
});
let fileData = fileResponse.body;
await lib.discord.channels['@0.2.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `This is the file you just sent!`,
filename: fileMetadata.filename,
file: fileData
});