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.