TypeError: Cannot read properties of undefined (reading 'encoded') on skip function

execute: async ({ args, context }) => {
const { position } = args;
const { message, discordClient } = context;
const guildId = message.guild?.id;

if (!guildId) {
return "This command can only be used inside a server.";
}

const player = discordClient.manager.players.get(guildId);

if (!player) {
return "No player is currently active in this server.";
}

if (!player.queue.size) {
return "There are no more songs in the queue.";
}

try {
const pos = (!position || position < 1) ? 1 : position;

if (pos > player.queue.size) {
return `Invalid position. The queue only has ${player.queue.size} song(s).`;
}

const skippedTrack = player.current;

player.skip(pos);

if (pos === 1) {
return `Skipped **${skippedTrack?.title || "Unknown Track"}**!`;
} else {
return `Skipped ahead to song #${pos} in the queue!`;
}

} catch (error) {
console.error("[skip tool] Error skipping track:", error);
return "Oops! Something went wrong trying to skip the track.";
}
}
};
execute: async ({ args, context }) => {
const { position } = args;
const { message, discordClient } = context;
const guildId = message.guild?.id;

if (!guildId) {
return "This command can only be used inside a server.";
}

const player = discordClient.manager.players.get(guildId);

if (!player) {
return "No player is currently active in this server.";
}

if (!player.queue.size) {
return "There are no more songs in the queue.";
}

try {
const pos = (!position || position < 1) ? 1 : position;

if (pos > player.queue.size) {
return `Invalid position. The queue only has ${player.queue.size} song(s).`;
}

const skippedTrack = player.current;

player.skip(pos);

if (pos === 1) {
return `Skipped **${skippedTrack?.title || "Unknown Track"}**!`;
} else {
return `Skipped ahead to song #${pos} in the queue!`;
}

} catch (error) {
console.error("[skip tool] Error skipping track:", error);
return "Oops! Something went wrong trying to skip the track.";
}
}
};
TypeError: Cannot read properties of undefined (reading 'encoded')

at Player.skip (/app/node_modules/moonlink.js/dist/src/entities/Player.js:268:39)

at Object.execute (/app/utils/music/tools/skip.js:48:20)

at /app/utils/music/LoadTools.js:30:25

at MusicHandler (/app/utils/music/musicHandler.js:154:50)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: Cannot read properties of undefined (reading 'encoded')

at Player.skip (/app/node_modules/moonlink.js/dist/src/entities/Player.js:268:39)

at Object.execute (/app/utils/music/tools/skip.js:48:20)

at /app/utils/music/LoadTools.js:30:25

at MusicHandler (/app/utils/music/musicHandler.js:154:50)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
34 Replies
Nonsen
NonsenOP•5d ago
track.requestedBy.id also undefined
hasselhoff
hasselhoff•5d ago
Oh, I had the same problem often and I don’t know how to fix it, so I just delete the player
MEE6
MEE6•5d ago
GG @hasselhoff, you just advanced to level 4!
hasselhoff
hasselhoff•5d ago
I don't have this problem now, maybe you need to update moonlink And this error also appears if someone tries to load unsupported links into your bot. For example, yandex music or vk music which is not supported in your lavalink or just a link to an mp3 file
Nonsen
NonsenOP•5d ago
Any prevention?
MEE6
MEE6•5d ago
GG @Nonsen, you just advanced to level 1!
hasselhoff
hasselhoff•5d ago
Just set up a link check
Nonsen
NonsenOP•5d ago
Or shell I host my own lavalink?
hasselhoff
hasselhoff•5d ago
To make the bot accept only links supported by your lavalink It will be better
Nonsen
NonsenOP•5d ago
I using free lavalink so they might unsupport?
hasselhoff
hasselhoff•5d ago
yes Just do
console.log(player)
console.log(player)
Nonsen
NonsenOP•5d ago
Oh and how about access the track.requestedBy.id also undefined
hasselhoff
hasselhoff•5d ago
And u see all info about your lavalink This is a useless feature and I advise you to remove it because no one uses it.
Nonsen
NonsenOP•5d ago
player.position?
hasselhoff
hasselhoff•5d ago
And it seems like the GuildMember object is simply stored there, and try logging track.requestedBy Do you want to add a function that will show the number of the next tracks?
Nonsen
NonsenOP•5d ago
yes
hasselhoff
hasselhoff•5d ago
By default this function is not there and you have to implement it yourself somehow
Nonsen
NonsenOP•5d ago
The docs kindda unreliable
hasselhoff
hasselhoff•5d ago
I used to assign each track its own number when uploading.
Nonsen
NonsenOP•5d ago
I mean to get the current time of the track
hasselhoff
hasselhoff•5d ago
But it worked very crookedly and that's why I removed it and just made numbers from 1-5 in the player itself а
hasselhoff
hasselhoff•5d ago
this one?
No description
Nonsen
NonsenOP•5d ago
exactly
hasselhoff
hasselhoff•5d ago
this is my func to get track time:
module.exports = {
convertTime: function (duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = parseInt((duration / 1000) % 60),
minutes = parseInt((duration / (1000 * 60)) % 60),
hours = parseInt((duration / (1000 * 60 * 60)) % 24);

hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

if (duration < 3600000) {
return minutes + ":" + seconds;
} else {
return hours + ":" + minutes + ":" + seconds;
}
},

convertNumber: function (number, decPlaces) {
decPlaces = Math.pow(10, decPlaces);

var abbrev = ["K", "M", "B", "T"];

for (var i = abbrev.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);

if (size <= number) {
number = Math.round((number * decPlaces) / size) / decPlaces;

if (number == 1000 && i < abbrev.length - 1) {
number = 1;
i++;
}

number += abbrev[i];

break;
}
}

return number;
},

chunk: function (arr, size) {
const temp = [];
for (let i = 0; i < arr.length; i += size) {
temp.push(arr.slice(i, i + size));
}
return temp;
},

convertHmsToMs: function (hms) {
var p = hms.trim().replace(/[. -]/g, ":").split(":"), // allow dots '.', spaces ' ' and hyphens '-' the same way as colons ':'
s = 0,
m = 1;

while (p.length > 0) {
s += m * parseInt(p.pop(), 10);
m *= 60;
}
return s * 1000;
},
};
module.exports = {
convertTime: function (duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = parseInt((duration / 1000) % 60),
minutes = parseInt((duration / (1000 * 60)) % 60),
hours = parseInt((duration / (1000 * 60 * 60)) % 24);

hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

if (duration < 3600000) {
return minutes + ":" + seconds;
} else {
return hours + ":" + minutes + ":" + seconds;
}
},

convertNumber: function (number, decPlaces) {
decPlaces = Math.pow(10, decPlaces);

var abbrev = ["K", "M", "B", "T"];

for (var i = abbrev.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);

if (size <= number) {
number = Math.round((number * decPlaces) / size) / decPlaces;

if (number == 1000 && i < abbrev.length - 1) {
number = 1;
i++;
}

number += abbrev[i];

break;
}
}

return number;
},

chunk: function (arr, size) {
const temp = [];
for (let i = 0; i < arr.length; i += size) {
temp.push(arr.slice(i, i + size));
}
return temp;
},

convertHmsToMs: function (hms) {
var p = hms.trim().replace(/[. -]/g, ":").split(":"), // allow dots '.', spaces ' ' and hyphens '-' the same way as colons ':'
s = 0,
m = 1;

while (p.length > 0) {
s += m * parseInt(p.pop(), 10);
m *= 60;
}
return s * 1000;
},
};
Nonsen
NonsenOP•5d ago
So you create your own function to track current time? The function that they gave us not avaliable?
hasselhoff
hasselhoff•5d ago
const position = currentTrack?.position || 0;
const currentTrackLength = currentTrack?.duration || 0;
const progress = currentTrackLength ? position / currentTrackLength : 0;


Write this code in your player menu, to show current time: ${progressBar} — ${convertTime(position, true)} / ${convertTime(currentTrackLength, true
const position = currentTrack?.position || 0;
const currentTrackLength = currentTrack?.duration || 0;
const progress = currentTrackLength ? position / currentTrackLength : 0;


Write this code in your player menu, to show current time: ${progressBar} — ${convertTime(position, true)} / ${convertTime(currentTrackLength, true
like this This function converts the timestamp given by moonlink to normal time.
Nonsen
NonsenOP•5d ago
Yes I know how to convert time but the player.position always give 0
hasselhoff
hasselhoff•5d ago
I have never used it I always assigned the numbers myself
Nonsen
NonsenOP•5d ago
ok than thank you! Last question which lavalink node you suggest
hasselhoff
hasselhoff•5d ago
How is that? I have my own
Nonsen
NonsenOP•5d ago
I think about to host my own I am not sure which one to pick
hasselhoff
hasselhoff•5d ago
Better host your own
Nonsen
NonsenOP•5d ago
Lavalink Docs
Standalone audio sending node based on Lavaplayer.
hasselhoff
hasselhoff•5d ago
yes

Did you find this page helpful?