Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda