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

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