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

241
Visualizações
Discord.js channel setName not triggering on setInterval

i have made a discord bot that does a few things on a few servers, one of the features to display the date/time as a channel name, i have one that is written the same way that display the member count and refreshes but the date time one just seems to run once then never change the name again.

const events = {};

const getDateTime = (format) => {
  format = format  || "d/m/y h:i"
  var now     = new Date(),
      year    = now.getFullYear(),
      month   = now.getMonth()+1, 
      day     = now.getDate(),
      hour    = now.getHours(),
      minute  = now.getMinutes(),
      second  = now.getSeconds(); 
  if(month.toString().length == 1) {
        month = '0'+month;
  }
  if(day.toString().length == 1) {
        day = '0'+day;
  }   
  if(hour.toString().length == 1) {
        hour = '0'+hour;
  }
  if(minute.toString().length == 1) {
        minute = '0'+minute;
  }
  if(second.toString().length == 1) {
        second = '0'+second;
  }   
  return format.replace("d", day)
                .replace("m", month)
                .replace("y", year)
                .replace("h", hour)
                .replace("i", minute)
                .replace("s", second)
}

module.exports = (client, guildId, channelId, format) => {
  const guild = client.guilds.cache.get(guildId);

  events[guildId] = setInterval(()=> {
    const channel = guild.channels.cache.get(channelId);
    const date =  getDateTime(format);
    const clock = "🕒 ";
    channel.setName(date);
  }, 1000 * 60);
}

module.exports.list = () => {
  return events;
}

module.exports.stop = (guildId) => {
  clearInterval(events[guildId]);
}

this is then run by calling it like

const guildDateTime = require("./guildDateTime");
// inside the client.on("ready")
client.guilds.cache.forEach(guild => {
  // other guild based features
  guildMemberCount(client, guild.id, channelConfig.memberCount.channel)
  guildDateTime(client, guild.id, channelConfig.dateTime.channel, channelConfig.dateTime.format);
});

i have put console.log in the setInterval it is being called and it is repeating but the channel name only changes the once then never changes again, this method is used on another function that does the similar for renaming it to the member count, this works perfect with no issues.

is there something im missing from this.

anyone with any ideas.

about 4 years ago · Juan Pablo Isaza
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