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

131
Vistas
Having one text.txt file and the bot chooses a component of it randomly with discord.js

i want to make a joke bot. (just for some friends on my server). I dont want to use an api. But instead make a big text.txt file with the jokes in it. I managed to let the bot respond when I message: test. It responds with a "joke" from the txt file. It only haves one joke in it tough. Now I want to have more jokes in it. And let the bot randomly choose from one of the jokes. The thing is, I dont know how to make the jokes be seperated so the bot can actually choose randomly from it. Here is my code so far:

client.on("message", msg => {
  var textart = fs.readFileSync('./textart.txt', {"encoding": "utf-8"})
  if(msg.content === `test`) {
     msg.channel.send(textart)
  }
  
  
})

I also dont know how to make the bot choose randomly between those jokes too( I'm an beginner so I need some more help with coding) Is there someone thats able to help me out?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

text txt

Joke 1
Joke 2
const jokes = textart.split(/\n/) // or "\n"
msg.channel.send(jokes[Math.floor(Math.random() * jokes length)])
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