I'm making an discord bot were people can upload there own jokes. I'm testing an very basic version of this idea and it's kinda working like expected. Here is my code:
client.on('message', msg => {
const fs = require('fs');
if(msg.content === "ff"){
let con = (msg.content);
const content = `${con}`;
fs.appendFile('textart.txt',content, err => {
if (err) {
console.error(err)
return
}
})
}
})
Using fs it's simple to write an input down in a txt file. But I want that when a new joke is given it makes a new line in the txt file. So like this:
1 joke one
2 joke two
3 joke three
But when I'm using this code it does this in the txt file :
1 joke one joke two joke three
How can make it so when a new joke is given the bot creates a new line and puts the joke in that new line. I found something and they said too use /n/ but I dont know how to use that in my code. Anyone haves an idea?
I was expecting the text file to have rows with inputs like described above
Use \n, and for the numbers, see how many newlines there are
const line = fs.readFileSync("textart.txt", "utf8").split("\n").length
const content = `${line} ${con}\n`
Note that for the numbers to be accurate, you need to have a linebreak from the start, so it should look like this from the start:
1 joke one