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

99
Views
Discord bot set presence updating the data

I wanna share on the presence status the number of guilds the bot is in.

let activities = [
    "!help",
    `on ${client.guilds.cache.size} servers`,
];

setInterval(() => {
    //generate random number between 1 and list length.
    const randomIndex = Math.floor(Math.random() * activities.length);
    const newActivity = activities[randomIndex];
    client.user.setActivity(newActivity);
}, 10000);

Source, from other stakoverflow question. But this does not solve my problem.

This way you will only get the number of guilds at the moment of starting the bot, but it will not be updated. So I did this:

    let activities = [
    "!help",
    `on ${client.guilds.cache.size} servers`,
    ];

setInterval(() => {
    let guildCount = client.guilds.cache.size;

    activities = [
        "!help",,
        `on ${guildCount} servers`,
    ];
}, 600000);

setInterval(() => {
    const randomIndex = Math.floor(Math.random() * activities.length);
    const newActivity = activities[randomIndex];
    client.user.setActivity(newActivity);
}, 10000);

Do you know any way to do it without having 2 set intervals. Is it not recommended to have unnecessary intervals?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could put the activities array inside your interval function.

setInterval(() => {
    let activities = [
    "!help",
    `on ${client.guilds.cache.size} servers`,
     ];
    //generate random number between 1 and list length.
    const randomIndex = Math.floor(Math.random() * activities.length);
    const newActivity = activities[randomIndex];
    client.user.setActivity(newActivity);
}, 10000);
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!