简体   繁体   中英

How to save file from user to variable discord.js

I have been trying to get my discord bot to be able to accept a user input from a slash command prompt of drop-uploading files, and then write that file locally in my repl.it, but I have had no such success. So far, all I have been able to do is create an empty file with the same name as the file uploaded, but I can't seem to get fs() to correctly accept the input, sorry for the paragraph and possibly bad grammar, I have been up for 32 hours this round of coding. Any answers would be greatly appreciated. Also, tell me how I can improve my questions please.

Edit:

The following code does not work, when I try uploading the file, it writes undefined

message.attachments.forEach(a => {
        fs.writeFileSync(`./${a.name}`, `${a.file}`); // Write the file to the system synchronously.
    });

I created some working code from discordjs.org's guides, here it is

fs.appendFile(filePath, `${os.EOL}${args[1]}`, function (error) {
            if (error) return log.error(error);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM