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

123
Views
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 answers
Answer question

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 Report

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