Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Write a input from a message to a txt file with Discord.js

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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda