From 7962266b26a2969feb617a3580f5ce0e2d93dbcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Mon, 7 Aug 2023 16:21:29 +0200 Subject: [PATCH] GeneralUtil: Add download file function --- util/general.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/general.js b/util/general.js index 316d978..1b7b53a 100644 --- a/util/general.js +++ b/util/general.js @@ -1,6 +1,8 @@ const { Bot } = require("../models"); const crypto = require("crypto"); const { ReactionUserManager } = require("discord.js"); +const axios = require("axios"); +const fs = require("fs"); module.exports = { name: "GeneralUtils", @@ -35,5 +37,10 @@ module.exports = { } return num; - } + }, + + downloadFile: async function(url, path) { + let imageBuffer = await axios.get(url, { responseType: 'arraybuffer' }); + fs.writeFileSync(path, imageBuffer.data); + }, }