- A Discord bot and its token.
- A Discord server in which you have access to grant the bot necessary access/permissiosn, and also Channel ID for the channel the Bot will use.
- A prior understanding of Discord Bots and Permissions helps but is not necessary. (Bonus just in case: The bot needs to be in the server whose Channel ID you give it to, and have embed perms)
I have only tested it for singler-server use for storing stuff in a server of your choice. I don't know how, if at all it would safely send to multiple channels.
- This is a project using nodeJS, its built-in https module and the Discord API. It uses discord as a file storage.
- It sends/uploads a file to discord through a frontend, then saves its message ID to retrieve it when needed. All you have to do is use its filename to do so. the message ID has to be saved and filename has to be correct to do so.
- The size of the file sent can theoretically be ANY SIZE. All you would need is pass the right Formidable options. And of course have the initial storage and time to send the file. Server side.
- Once sent the file will be deleted from the /uploads directory because it is assumed that the file sent from the frontend, once sent will be deleted from your local storage, as such make sure you have a copy of the file just in case you need to keep it.
- Instead it is stored in and can be retrieved from discord.
- This can be made simpler through express with node if you like, but I would recommend against somelthing like Discordjs.
- Formidable was the only one I could rely on to safely send multipart/form-data.(10/10 personally, I tried a few others but Formidable was the best/safest)
- It uses Streams to both chunk and unchunk/compile the bigger files. It is slow, so implementing concurrency would be wonderful.
- It uses a single .txt file to store the filenames and a .json file to store IDs/metadata. Implementing a backend would be easy but given its limited scope of personal use, this is sufficient for now.
- I have not cleared the received_files.txt and messageIDs.json files, but I would suggest you do erase them clean once you look at their format.
- The chunk size is set to 8-10 MB but you can change it to 500 if you have Nitro. That is the Discord filesize limit.
If you (the reader) plan to use this code, do ensure you correctly put the channel ID and bot token in their correct places (be it the variables or in options directly which I recommend for personal use).
The files you would need to go to(All of which are in the backend folder) are chunker.js, sender.js and retriever.js where the header options are used to make the requests.
Other changes you can make are to reciever.js which initializes the Formidable form. In const options, change the maxFileSize as you see fit.