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

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

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