Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!