'How to delete a voice channel when everybody disconnects?

I created a join to create system that creates a channel when a user join and delete it when they leave. However, it only deletes if the last person that's leaving is the user who created the room. Any ideas?

const { Collection } = require("discord.js");
const voiceCollection = new Collection();

module.exports = async (Discord, client, oldState, newState) => {
  const user = await client.users.fetch(newState.id);
  const member = newState.guild.member(user);

  // JOIN
  if (!voiceName || voiceName === "") {
    if (!oldState.channel && newState.channelID === "898245212541976667") {
      const channel = await newState.guild.channels.create(user.tag, {
        type: "voice",
        parent: newState.channel.parent,
      });
      member.voice.setChannel(channel);
      voiceCollection.set(user.id, channel.id);
      await channel.overwritePermissions([
        {
          id: user.id,
          allow: ["MANAGE_CHANNELS", "CONNECT"],
        },
        {
          id: member.guild.id,
          deny: ["CONNECT"],
        },
      ]);
    } else if (!newState.channel) {
      if (oldState.channelID === voiceCollection.get(newState.id)) {
        if (oldState.channel.members.size < 1) {
          return oldState.channel.delete();
        }
      }
    }


Solution 1:[1]

var newchannel_id = config.Channel_id; var category_id = config.category;

var userchannellist = []

client.login(token); client.on('voiceStateUpdate', async (oldMember, newMember) => {

    if (newMember.channel !== null && oldMember.channel === null && newMember.channel.id === newchannel_id || newMember.channel !== null && oldMember.channel !== null && newMember.channel.id === newchannel_id) {
        var current_user = newMember.member.user;
        console.log(current_user.username + 'creating the channel');

        // Start the creation of the new channel
        var server = newMember.guild;
        let USERA = newMember.member.nickname || newMember.member.user.username;

        var channel = {
            type: 'voice', bitrate: 384000, parent: category_id, permissionOverwrites: [{
                // permissions
                id: server.id, allow: ['VIEW_CHANNEL'],
            },
            {
                id: current_user.id, allow: ['MOVE_MEMBERS', 'MANAGE_CHANNELS']
            }
            ]
        };
        server.channels.create('?' + USERA, channel).then(channel => {
            newMember.setChannel(channel).catch(console.error)
            userchannellist.push(channel)
            //channel region
            client.api.channels(channel.id).patch({ data: { rtc_region: "rotterdam" } })
        }).catch(console.error);
    }

    // delete Chaneel
    if (oldMember.channel) {
        let filter = (ch) =>
            (ch.parentID == category_id)
            && (ch.id !== newchannel_id)
            && (oldMember.channel == ch.id)
            && (oldMember.channel.members.size == 0);

        return oldMember.guild.channels.cache
            .filter(filter)
            .forEach((ch) => ch.delete()
            .catch(console.error));
    }
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 i_Moohd_