Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"leaveOnEmpty" and "channelEmpty" not working #912

Closed
StarJules opened this issue Dec 2, 2021 · 5 comments · Fixed by #1210
Closed

"leaveOnEmpty" and "channelEmpty" not working #912

StarJules opened this issue Dec 2, 2021 · 5 comments · Fixed by #1210
Labels
bug Something isn't working

Comments

@StarJules
Copy link

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

@StarJules StarJules added the bug Something isn't working label Dec 2, 2021
@rastiqdev
Copy link

I have the same problem.

@Loadren
Copy link

Loadren commented Dec 26, 2021

Same problem here.

Passing parameter to the queue, not the player. Also, did leaveOnEndCooldown just stopped working?

@LePtitMetalleux
Copy link
Contributor

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

These options must be passed in the crequeQueue() method (refers to https://discord-player.js.org/docs/main/master/class/Player?scrollTo=createQueue)
image

Same problem here.

Passing parameter to the queue, not the player. Also, did leaveOnEndCooldown just stopped working?

The option is leaveOnEmptyCooldown not leaveOnEndCooldown, but it doesn't work for me as well

@MrTheBank
Copy link

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.

@EwoX07
Copy link
Contributor

EwoX07 commented Jan 12, 2022

# #986

@twlite twlite linked a pull request Mar 28, 2022 that will close this issue
@twlite twlite linked a pull request Jul 19, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
6 participants