Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
604 stars 192 forks source link

channelEmpty and botDisconnect does not work #993

Closed Hype8585 closed 2 years ago

Hype8585 commented 2 years ago

I know my code is right because I have not change a single thing see below.

player.on('error', (queue, error) => {
    console.log(`Error emitted from the queue ${error.message}`);
});

player.on('connectionError', (queue, error) => {
    console.log(`Error emitted from the connection ${error.message}`);
});

player.on('trackStart', (queue, track) => {
    if (!client.config.opt.loopMessage && queue.repeatMode !== 0) return;
    queue.metadata.send(`Started playing ${track.title} in **${queue.connection.channel.name}** 🎧`);
});

player.on('trackAdd', (queue, track) => {
    queue.metadata.send(`Track ${track.title} added in the queue ✅`);
});

player.on('botDisconnect', (queue) => {
    queue.metadata.send('I was manually disconnected from the voice channel, clearing queue... ❌');
});

player.on('channelEmpty', (queue) => {
    queue.metadata.send('Nobody is in the voice channel, leaving the voice channel... ❌');
});

player.on('queueEnd', (queue) => {
    queue.metadata.send('I finished reading the whole queue ✅');
});

CODE

        if (!args[0]) return message.channel.send(`${message.author}, ⚠️ - Usage: +play <song name>`);

        const res = await player.search(args.join(' '), {
            requestedBy: message.member,
            searchEngine: QueryType.AUTO
        });

        if (!res || !res.tracks.length) return message.channel.send(`${message.author}, ⚠️ - No results found`);

        const queue = await player.createQueue(message.guild, {
            leaveOnEnd: true, //leaveOnEndCooldown doesnt work anymore
            leaveOnEmpty: true,
            channelEmpty: true,
            leaveOnEmptyCooldown: 20000, //Or use `leaveOnEmpty: false` to stay in the vc 24/7, 20000 (ms) is 20s
            metadata: message.channel
        });
        try {
            if (!queue.connection) await queue.connect(message.member.voice.channel);
        } catch {
            await player.deleteQueue(message.guild.id);
            return message.channel.send(`${message.author}, ⚠️ - I can't join the voice channel`);
        }

        await message.channel.send(`${message.author}, 🎧 - Loading your ${res.playlist ? 'playlist' : 'track'}`);

        res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]);

        if (!queue.playing) await queue.play();
    },
};
loveisglitchy commented 2 years ago

There may be a version mismatch somewhere. Can you uninstall and reinstall the package with "@latest" tag and try again?

Hype8585 commented 2 years ago

Its not. Here I will send you my whole package.json.

{
  "name": "test",
  "version": "1.0.0",
  "description": "Music-Bot",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "test",
  "license": "ISC",
  "dependencies": {
    "@discordjs/voice": "^0.7.5",
    "@distube/spotify": "^1.0.0",
    "ascii-table": "^0.0.9",
    "distube": "^3.1.0",
    "glob": "^7.2.0",
    "libsodium-wrappers": "^0.7.9",
    "yt-search": "^2.10.3",
    "ytdl-core": "^4.10.0",
    "canvacord": "^5.2.1",
    "discord-canvas": "^1.4.1",
    "node-pre-gyp": "0.12.0",
    "nuggies": "github:Nuggies-Bot/Nuggies-npm#dev",
    "ultrax": "^1.9.3",
    "fs": "^0.0.1-security",
    "mongoose": "^6.0.12",
    "path": "^0.12.7",
    "chalk": "^4.1.2",
    "discord-xp": "^1.1.16",
    "discord-nsfw": "^1.3.0",
    "djs-utils": "^1.1.2",
    "pretty-ms": "^7.0.1",
    "mathjs": "^10.0.0",
    "weather-js": "^2.0.0",
    "marvalx": "^2.7.9",
    "djs-misc": "^1.0.1",
    "quick.db": "^7.1.3",
    "djs-games": "^2.1.10",
    "node-opus": "^0.3.3",
    "@discordjs/opus": "^0.7.0",
    "discord-player": "^5.2.0",
    "discord.js": "^13.6.0",
    "ffmpeg-static": "^4.4.1",
    "ms": "^2.1.3",
    "opusscript": "^0.0.8",
    "@discord-player/extractor": "^3.0.2",
    "@discord-player/downloader": "^3.0.1",
    "play-dl": "^1.7.8"
  },
  "engines": {
    "node": "16.13.2",
    "npm": "8.1.2"
  }
}
Hype8585 commented 2 years ago

@loveisglitchy

loveisglitchy commented 2 years ago

Androz may not have the package updated to cope fully with djs v13.6. See if it works on 13.5 era.

dotnize commented 2 years ago

972 #986

Hype8585 commented 2 years ago

I still don't get it...

LePtitMetalleux commented 2 years ago

Theses events are currently broken, wait for an update to fix it

Hype8585 commented 2 years ago

Oh okay. Thanks for letting me know.