question-mark
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: message.channel, 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

1reaction
MrTheBankcommented, Dec 30, 2021

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

endTimeout.js

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

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

    clearTimeout(queue) {
        let timeout = this.timeouts.get(queue.guild.id);
        if (timeout) {
            clearTimeout(timeout);
            this.timeouts.delete(queue.guild.id);
        }
    }
}

player-handler.js

player
    .on('trackAdd', (queue, track) => {
        endTimeout.clearTimeout(queue);
    })
    .on('tracksAdd', (queue, track) => {
        endTimeout.clearTimeout(queue);
    })
    .on('channelEmpty', (queue => {
        endTimeout.clearTimeout(queue);
    }))
    .on('queueEnd', (queue => {
        endTimeout.setTimeout(queue);
    }))
    .on('botDisconnect', (queue => {
        endTimeout.clearTimeout(queue);
    }))
    ;

Hope this will work for you.

0reactions
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 - npm.io
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found