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β€’6mo ago
track.requestedBy.id also undefined
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
GG @hasselhoff, you just advanced to level 4!
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
Any prevention?
MEE6
MEE6β€’6mo ago
GG @Nonsen, you just advanced to level 1!
hasselhoff :3
hasselhoff :3β€’6mo ago
Just set up a link check
Nonsen
NonsenOPβ€’6mo ago
Or shell I host my own lavalink?
hasselhoff :3
hasselhoff :3β€’6mo ago
To make the bot accept only links supported by your lavalink It will be better
Nonsen
NonsenOPβ€’6mo ago
I using free lavalink so they might unsupport?
hasselhoff :3
hasselhoff :3β€’6mo ago
yes Just do
console.log(player)
console.log(player)
Nonsen
NonsenOPβ€’6mo ago
Oh and how about access the track.requestedBy.id also undefined
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
player.position?
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
yes
hasselhoff :3
hasselhoff :3β€’6mo ago
By default this function is not there and you have to implement it yourself somehow
Nonsen
NonsenOPβ€’6mo ago
The docs kindda unreliable
hasselhoff :3
hasselhoff :3β€’6mo ago
I used to assign each track its own number when uploading.
Nonsen
NonsenOPβ€’6mo ago
I mean to get the current time of the track
hasselhoff :3
hasselhoff :3β€’6mo 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 :3
hasselhoff :3β€’6mo ago
this one?
No description
Nonsen
NonsenOPβ€’6mo ago
exactly
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
So you create your own function to track current time? The function that they gave us not avaliable?
hasselhoff :3
hasselhoff :3β€’6mo 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β€’6mo ago
Yes I know how to convert time but the player.position always give 0
hasselhoff :3
hasselhoff :3β€’6mo ago
I have never used it I always assigned the numbers myself
Nonsen
NonsenOPβ€’6mo ago
ok than thank you! Last question which lavalink node you suggest
hasselhoff :3
hasselhoff :3β€’6mo ago
How is that? I have my own
Nonsen
NonsenOPβ€’6mo ago
I think about to host my own I am not sure which one to pick
hasselhoff :3
hasselhoff :3β€’6mo ago
Better host your own
Nonsen
NonsenOPβ€’6mo ago
Lavalink Docs
Standalone audio sending node based on Lavaplayer.
hasselhoff :3
hasselhoff :3β€’6mo ago
yes

Did you find this page helpful?