Revolt Uploader
Revolt.js doesn't offer the ability to upload attachments, so here is a utility package to allow easy file uploads.
Installation
npm install revolt-uploader
It's as easy as that! :)
Usage
First, you have to import and initialize an uploader object.
const Uploader = require("revolt-uploader");
const uploader = new Uploader(client);
Now you've got your uploader. All you have to do is to login your bot client using client.login("token")
After that, you can upload files to revolt's servers using the uploadFile
method.
client.on("message", (message) => {
Promise.allSettled([
uploader.uploadFile("path/to/file", "file"),
uploader.uploadFile("path/to/another/file", "another-file"),
]).then(attachments => {
attachments = attachments.map(attachment => attachment.value);
message.channel.sendMessage({
content: "Here is your file!",
attachments: attachments
});
});
message.channel.sendMessage({
content: "Here is your file!",
attachments: [await uploader.uploadFile("/path/to/another/file", "file-name")]
});
});
Uploading URLs
You can upload files from urls by using the uploadUrl
method. It will stream the file from the url to autumn without saving the image on your machine.
It works just like a normal file upload:
const id = await uploader.uploadUrl("url", "fileName");
Advanced usage
If you need to upload anything else than existing files, use the .upload(fileData, fileName)
method.
You can use any kind of data object for the fileData but have to specify the file name.
For example using a stream:
const https = require("https");
client.on("message", (message) => {
https.get("<url>", (response) => {
message.channel.sendMessage({
content: "Downloaded file: ",
attachments: [await uploader.upload(response, "file.filetype")]
});
});
});
Furthermore, it is possible to upload your content under different tags. The default tag is attachments
. These tags are available:
attachments
avatars
backgrounds
icons
banners
emojis
All of these have different configurations and limits. See this file for the exact specifications.