Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda