Start playing the wrong track

Currently we have the problem when the player is destroyed and then recreated that it starts for 3 seconds with the old track, but then cancels it and starts again with the right one.
Solution:
Thank you 🙂
Jump to solution
22 Replies
1Lucas1.apk
1Lucas1.apk•6mo ago
This seems to me to be a problem with lavalink/nodelink or alternatively, moonlink only instructs the server, It could be a problem on our side in destroying the player, I will investigate tomorrow I'm from Brazil and it's night Can you provide me with moonlink logs?
MEE6
MEE6•6mo ago
GG @1Lucas1.apk, you just advanced to level 41!
1Lucas1.apk
1Lucas1.apk•6mo ago
You can put a parameter to save in file there you upload here
logFile: {
log: true,
path: "moonlink.log",
},
logFile: {
log: true,
path: "moonlink.log",
},
Rest assured that it will only save the package, I need this to know what is happening If possible, send me full, not in parts, I need the details
BastiGameツ
BastiGameツOP•6mo ago
I also left the Voice Channel at the end. But I don't see the destroy in the log file. But the bot leaves the voice channel. Is that perhaps the problem?
1Lucas1.apk
1Lucas1.apk•6mo ago
I see that when you enter the channel, create the player, wait for the voice information and play Zorro - Heaven Was Mine after All Then it is destroyed, and applied at the end of the loop. But you only got the player information I really want everything To see if there is any abnormality in Rest, etc.
BastiGameツ
BastiGameツOP•6mo ago
this is all that is in the log file
1Lucas1.apk
1Lucas1.apk•6mo ago
Are you using Lavalink?
MEE6
MEE6•6mo ago
GG @BastiGameツ, you just advanced to level 2!
1Lucas1.apk
1Lucas1.apk•6mo ago
I got ready, already went to make a Commit Pro Dev
1Lucas1.apk
1Lucas1.apk•6mo ago
@BastiGameツ npm install git+https://github.com/Ecliptia/moonlink.js.git#dev
GitHub
GitHub - Ecliptia/moonlink.js: MoonLink.js is a simple package for ...
MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use. - GitHub - Ecliptia/moonlink.js: MoonLink.js is a simpl...
1Lucas1.apk
1Lucas1.apk•6mo ago
I could test for me, I made a change that worked for me
BastiGameツ
BastiGameツOP•6mo ago
okay, i would test it The fact that the bot now takes longer may also be due to the fact that I tested it locally. Unfortunately, I can't test it directly on the host at the moment.
1Lucas1.apk
1Lucas1.apk•6mo ago
The change I made is to check if the loop is activated, but from the logs, the loop is being activated after the player is destroyed [2025-04-26T15:50:57.763Z] Moonlink.js - Player > Player for guildId 1364543610200002634 has been deleted [2025-04-26T15:50:57.836Z] Moonlink.js > Player 1364543610200002634 is looping the track. When loop is activated, some tracks may come with the last team that played, so we should return to position 0, but as this is about destruction There is something assigning a value And the database recognizes this It needs to be before destruction The bot I tested is in the repository in the dev branch, testBot/index.js folder
BastiGameツ
BastiGameツOP•6mo ago
static async leaveAndStop(voiceChannel, client, guild) {
if (voiceChannel.members.size > 1) return;

const player = client.moonlink.getPlayer(guild.id);
if (!player && !player?.connected) return;
player.destroy();

}

static async #play(client, voiceChannel, guild, trackUrl) {
const player = client.moonlink.getPlayer(guild.id) || client.moonlink.createPlayer({
guildId: guild.id,
voiceChannelId: voiceChannel.id,
textChannelId: voiceChannel.id,
volume: 50,
loop: 'track'
});


if (player.playing) return

player.connect({ setDeaf: true });

const result = await client.moonlink.search({
query: trackUrl,
})

const track = result.tracks[0];

player.queue.clear();
player.queue.add(track);

await player.play().catch(error => {
Logger.error(LogModule.AUDIO, null, error?.message, error?.stack);
});
}
static async leaveAndStop(voiceChannel, client, guild) {
if (voiceChannel.members.size > 1) return;

const player = client.moonlink.getPlayer(guild.id);
if (!player && !player?.connected) return;
player.destroy();

}

static async #play(client, voiceChannel, guild, trackUrl) {
const player = client.moonlink.getPlayer(guild.id) || client.moonlink.createPlayer({
guildId: guild.id,
voiceChannelId: voiceChannel.id,
textChannelId: voiceChannel.id,
volume: 50,
loop: 'track'
});


if (player.playing) return

player.connect({ setDeaf: true });

const result = await client.moonlink.search({
query: trackUrl,
})

const track = result.tracks[0];

player.queue.clear();
player.queue.add(track);

await player.play().catch(error => {
Logger.error(LogModule.AUDIO, null, error?.message, error?.stack);
});
}
This is the code we currently have. It does not work with this one. But I don't see any difference to your code
1Lucas1.apk
1Lucas1.apk•6mo ago
I think I know the problem, I'll fix it
1Lucas1.apk
1Lucas1.apk•6mo ago
@BastiGameツ npm install git+https://github.com/Ecliptia/moonlink.js.git#dev
GitHub
GitHub - Ecliptia/moonlink.js: MoonLink.js is a simple package for ...
MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use. - GitHub - Ecliptia/moonlink.js: MoonLink.js is a simpl...
1Lucas1.apk
1Lucas1.apk•6mo ago
I made another change Now I did it right and it seems to have gone Package was processing data even if the player was destroyed, then I made a parameter to ensure that I do not happen it
1Lucas1.apk
1Lucas1.apk•6mo ago
No description
BastiGameツ
BastiGameツOP•6mo ago
thank you very much. Do you make a new release for this? We don't want to use the dev branch for the live bot. And can i maybe have the bug hanter role 🙂
1Lucas1.apk
1Lucas1.apk•6mo ago
I will launch this when one of the source is finished inside the package It can be :hi:
Solution
BastiGameツ
BastiGameツ•6mo ago
Thank you 🙂

Did you find this page helpful?