Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Tener un archivo text.txt y el bot elige un componente al azar con discord.js

quiero hacer una broma bot. (solo para algunos amigos en mi servidor). No quiero usar una API. Pero en su lugar, haga un gran archivo text.txt con los chistes en él. Me las arreglé para dejar que el bot respondiera cuando envié un mensaje: prueba. Responde con una "broma" del archivo txt. Solo tiene un chiste duro. Ahora quiero tener más chistes en él. Y deja que el bot elija al azar uno de los chistes. La cuestión es que no sé cómo separar los chistes para que el bot pueda elegirlos al azar. Aquí está mi código hasta ahora:

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

Tampoco sé cómo hacer que el bot elija aleatoriamente entre esos chistes (soy un principiante, así que necesito más ayuda con la codificación) ¿Hay alguien que pueda ayudarme?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

texto texto

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!