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

130
Visualizações
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 Respostas
Responde à pergunta

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 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