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

128
Vistas
why it shows just one of them in activity? discord js v13

i have this code :

con.query(`SELECT * FROM count WHERE default = 'true'`, (err, row) => {
        activities = [
            `${row[0].members} Members`,
            `${row[0].channels} Channels`
        ];
    });
    setInterval(() => {
        const randomIndex = Math.floor(Math.random() * (activities.length - 1) + 1);
        const newActivity = activities[randomIndex];
        client.user.setActivity(`${newActivity}`, { type: 'WATCHING' });
    }, 10000);

I checked sql everything is ok with mysql and it shows only one of them (it have to change status every 10 second but it doesn't work) and there is no error

thank you for your help

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

0

Remember that arrays in JavaScript start at 0 and the formula to get a random element from an array is array[Math.floor(Math.random() * array.length)];

In your case, you are using the formula activities[Math.floor(Math.random() * (activities.length - 1) + 1)]. Therefore, the array will always get index 1

about 4 years ago · Juan Pablo Isaza Denunciar

0

i got it. yeah it's true JavaScript start at 0 and formula to get a random element from an array is: var item = activities[Math.floor(Math.random() * activities.length)]; so i had to remove this : const newActivity = activities[randomIndex]; and make the activities like this :

Array( ${${row[0].members} Members, ${${row[0].channels} Channels );

thank you

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