Example of an Image/Video file or url conversion to buffer and posting to a different channel by a bot
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
module.exports = async (event, context) => {
let result = await lib.discord.channels['@0.2.0'].messages.retrieve({
message_id: event.id,
channel_id: `${process.env.Channel_to_upload}`
});
if (result.attachments[0] == null) {
console.log("empty");
return;
}
console.log(result.attachments[0].url);
console.log(result.attachments[0].content_type);
var vs = result.attachments[0].content_type;
var vsx = vs.slice(6, 9);
if (vsx === "qui") {
vsx = "mov";
}
if (vsx === "jpe") {
vsx = "jpg";
}
if (vsx === "x-m") {
vsx = "wmv";
}
let buffer = await lib.http.request['@1.1.5']({
method: 'GET',
url: `${result.attachments[0].url}`,
}).then((result) => {
return result.body;
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${process.env.Channel_to_send}`,
content: '',
file: Buffer.from(buffer),
filename: `${result.attachments[0].id}.${vsx}`,
});
await lib.discord.channels['@0.0.6'].messages.destroy({
message_id: event.id,
channel_id: `${process.env.Channel_to_upload}`, //replace with your channel id
});
}