In order to write a text file in JS you should use the fs
library, included in Node.js.
Here is an example of writing to a file:
fs = require('fs');
let content = "Hello world!";
fs.writeFile('file.txt', content, function (err) {
if (err) return console.log(err);
// Code here will execute if successfully written
});
Then in order to send a local file to Discord you can use .send
with an object containing a files
property in it, like this:
channel.send({
files: [{
attachment: 'entire/path/to/file.txt',
name: 'file.txt'
}]
}).then(() => {
// Delete file
fs.unlink('file.txt');
});
You can see more about .send()
here and you can find more about the fs
module here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…