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

194
Vistas
Discord.js - Bot is not leaving the channel if alone at the end of the queue

I'm kind of new to discord.js coding and I wanted to make my music bot stay in the channel forever, but if there are no people listening, it will quit at the end of the playing music queue.

This is what I tried:

const queue = message.client.queue.get(message.guild.id);

    if (!song) {

      const endembed = new MessageEmbed().setColor("#F0EAD6")
        .setAuthor(`Music Queue ended.`)

      if (queue.channel.members.size != 1)
      message.client.queue.delete(message.guild.id);
      return queue.textChannel.send(endembed).catch(console.error);

      if (!song) queue.channel.leave()
      message.client.queue.delete(message.guild.id);
      return queue.textChannel.send(endembed).catch(console.error);
    }

Problem is that the bot will not leave (if alone) at the end of the music playing.

So the bot needs to stay forever in the channel if there is someone in the channel that is not another bot, and leave the channel if the queue ends and there is no one in the channel.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try adding braces to your code like this:

    if (!song) {

         const endembed = new MessageEmbed().setColor("#F0EAD6").setAuthor(`Music Queue ended.`);

          if (queue.channel.members.size != 1){
              message.client.queue.delete(message.guild.id);
              return queue.textChannel.send(endembed).catch(console.error);
      }
    
          queue.channel.leave();
          message.client.queue.delete(message.guild.id);
          return queue.textChannel.send(endembed).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