Resends images and videos to a different channel. This was originally from vestrius of the same name but modified.
//Originally from vestrius: "Upload Images and Videos to a Channel From a Bot" snippet.
//Modified it to support multiple attachments.
//By Lilac🍥Syringa🌸.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const OutputChannel = `` //The channel where the bot will resend the attachments to. Make sure to add stuff here.
if (context.params.event.attachments[0] == null) {
console.log('empty'); //Stops the command if there are no attachments.
return;
}
var FileArray = new Array();
for (
let AttachmentNum = 0;
AttachmentNum < context.params.event.attachments.length;
AttachmentNum++
) {
console.log(`Set ${AttachmentNum}`);
console.log(context.params.event.attachments[AttachmentNum].url);
console.log(context.params.event.attachments[AttachmentNum].content_type);
var FileType = context.params.event.attachments[
AttachmentNum
].content_type.slice(6, 9);
switch (FileType) {
case `qui`:
FileType = `mov`;
break;
case `jpe`:
FileType = `jpg`;
break;
case `x-m`:
FileType = `wmv`;
break;
}
console.log(FileType);
var SpecificBuffer = await lib.http.request['@1.1.5']({
method: 'GET',
url: `${context.params.event.attachments[AttachmentNum].url}`,
}).then((result) => {
return result.body;
});
var CurrentFile = {
file: Buffer.from(SpecificBuffer),
filename: `${context.params.event.attachments[AttachmentNum].id}.${FileType}`,
};
CurrentFile + `,`;
FileArray.push(CurrentFile);
}
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${OutputChannel}`, //Output Channel
content: ``,
attachments: FileArray,
});
await lib.discord.channels['@0.0.6'].messages.destroy({
message_id: context.params.event.id,
channel_id: `${context.params.event.channel_id}`, //Input channel (Destroys the original message.)
});