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

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

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 Relatório

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