Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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();
        }
      }
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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));
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda