Search code examples
javascriptnode.jsdiscorddiscord.jsdistube

discord.js DisTube Error: 'CANNOT_RESOLVE_SONG'


I receive an error when I want to skip the current song. I previously added a song to the queue and when I print the queue, the song is there. But when I want to skip, I receive the following error:

E:\JavaScript\privatebot\node_modules\distube\dist\index.js:1330
    throw new DisTubeError("CANNOT_RESOLVE_SONG", song);
          ^

DisTubeError [CANNOT_RESOLVE_SONG]: Cannot resolve undefined to a Song
    at DisTubeHandler.resolve (E:\JavaScript\privatebot\node_modules\distube\dist\index.js:1330:11)
    at DisTube.play (E:\JavaScript\privatebot\node_modules\distube\dist\index.js:2244:33)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  errorCode: 'CANNOT_RESOLVE_SONG'
}

Thats my add to queue function:

[...]
const song = event.options.getString("songname");
const voice = event.member.voice.channel;
if (!voice) {
    event.reply({content: "You have to be in a voice to do this!", ephemeral: true})
} else {
    const result = event.client.DisTube.search(song, {limit: 5, type: "video"});
    result.then(res => {
        const s = new Song(res[0], {source: "youtube"}); // Creating a Song object for the queue
        console.log(res[0]);

        // "addToQueue()" is NOT in the documentation of DisTube... But it works??
        const q = event.client.DisTube.getQueue(event.guild).addToQueue(s, 1);

    })
            
[...]

Thats my skip function:

[...]
     await event.client.DisTube.skip(event.guild).then((song) => {
        console.log(song.name)
     });
[...]

Thank you for help!


Solution

  • I found the issue, it was the event "finishSong", there was code that said the bot should play something out of a .json file, but there wasn't another song. So the queue works, but I don't understand why there is no addToQueue() in the docs...