Currently, I am in the process of making some final adjustments to upgrade my Discord bot from version 11.4 to 12.
However, I have encountered an issue with private channels not being deleted after a specific period of time. I attempted to modify voiceChannel to voice.channel, but unfortunately, it did not resolve the problem.
Below is the code snippet:
bot.on("voiceStateUpdate", oldMember => {
deleteEmptyChannelAfterDelay(oldMember.voiceChannel);
});
function deleteEmptyChannelAfterDelay(voiceChannel, delayMS = 5000){
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
if(!voiceChannel.health) voiceChannel.health = 0;
voiceChannel.health += 1;
setTimeout(function(){
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
voiceChannel.health -= 1;
if(voiceChannel.health > 0) return;
if(!voiceChannel.name.includes('\'s Room')) return;
voiceChannel.delete()
.catch(error => console.log(error));
}, delayMS);
}
I tried seeking assistance on Discord.js guides and forums, but unfortunately, I could not find any solution. Any help would be greatly appreciated! Thank you.