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