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

228
Vistas
Math.floor(Math.random() * replies.length); not working
const replies = [
    "image 1",
    "image 2",
    "image 3",
    "image 4",
    "image 5"
];

const reply = Math.floor(Math.random() * replies.length);
const words = replies[reply]
   message.channel.send(words);

So i have this simple discord bot code which i supposed to reply with a random message from replies list, the bot works and everything but keep outputting the same message over and over instead of a random one (image 5)

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

It looks to me like your code works!

const replies = [
    "image 1",
    "image 2",
    "image 3",
    "image 4",
    "image 5"
];

const reply = Math.floor(Math.random() * replies.length);
const words = replies[reply]
console.log(words)

If you just console out words variable this appears to work how you want it to. You can see in the snippet that each time you run the code, a random image is returned.

As @3limin4to0r mentioned, this may be an issue with reusing the same index if you are running this multiple times.

about 4 years ago · Santiago Gelvez 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