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.
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);
}