Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"leaveOnEmpty" and "channelEmpty" not working

See original GitHub issue

Describe the bug When creating the queue with the option “leaveOnEmpty”, nothing happens when everyone leaves the channel. Also the “channelEmpty” event is never emitted.

To Reproduce When creating the queue add the option “leaveOnEmpty” to “true”. Exit the channel and the bot will keep playing. In the events, add the event “channelEmpty”. When everyone leaves the channel, nothing will be emitted.

Expected behavior In the “leaveOnEmpty”, the bot should disconnect when everyone leaves. In the “channelEmpty” event, when everyone leaves the channel, the event should be emitted.

Screenshots/Codes const queue = await player.createQueue(message.guild, { metadata:, autoSelfDeaf: true, leaveOnEnd: false, leaveOnStop: true, leaveOnEmpty: true, ytdlOptions: { quality: "highest", filter: "audioonly", highWaterMark: 1 << 25, dlChunkSize: 0, }, });

player.on("channelEmpty", async (queue) => {console.log("Example")}

Please complete the following information:

  • Node Version: 16.6.1
  • Discord Player Version: 5.2.0
  • Discord.js Version: 13.3.1

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

MrTheBankcommented, Dec 30, 2021

You need to create leaveOnEndCooldown handler by yourself, Maybe take a look of this code.


module.exports = class EndTimeout {
    constructor() {
        this.timeouts = new Map();

    setTimeout(queue) {
        let timeout = setTimeout(async () => {
            await queue.metadata.send({embeds: [new MessageEmbed()
                    .setDescription('เนื่องจากไม่มีความเคลื่อนไหว บอทจึงออกจากห้อง')]
        }, leave_on_end * 1000);
        this.timeouts.set(, timeout);

    clearTimeout(queue) {
        let timeout = this.timeouts.get(;
        if (timeout) {


    .on('trackAdd', (queue, track) => {
    .on('tracksAdd', (queue, track) => {
    .on('channelEmpty', (queue => {
    .on('queueEnd', (queue => {
    .on('botDisconnect', (queue => {

Hope this will work for you.

EwoX07commented, Jan 12, 2022

# #986

Read more comments on GitHub >

github_iconTop Results From Across the Web

creating a music bot and i get this TypeError - Stack Overflow
IntentsBitField is not a constructor at new Player (I:\Discord Music ... leaveOnEmpty) queue.destroy(true); this.emit("channelEmpty", ...
Read more >
discord-music-player - npm
Complete framework to facilitate music commands using discord.js v14 and v13.. Latest version: 9.1.1, last published: 3 months ago.
Read more >
Discord-music-player -
This package supports YouTube Videos & Playlists, Spotify Songs & Playlists, Apple Music Songs & Playlists. Package from version v7.0.0 is fully maintained...
Read more >
@jadestudios/discord-music-player - npm package | Snyk
No known security issues ... Minor updates may not work sometimes as well. ... { leaveOnEmpty: false, // This options are optional. }); ......
Read more >
Discord.JS | Music BOT | Not Working. : r/Discord_Bots - Reddit
I have a problem with my two music bots (which are only on my own ... leaveOnStop: true, leaveOnEmpty: true, leaveOnEmptyCooldown: 1000, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found