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•17h 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•17h ago
GG @1Lucas1.apk, you just advanced to level 41!
1Lucas1.apk
1Lucas1.apk•17h 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•13h 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•6h 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•6h ago
this is all that is in the log file
1Lucas1.apk
1Lucas1.apk•5h ago
Are you using Lavalink?
MEE6
MEE6•5h ago
GG @BastiGame惄, you just advanced to level 2!
1Lucas1.apk
1Lucas1.apk•5h ago
I got ready, already went to make a Commit Pro Dev
1Lucas1.apk
1Lucas1.apk•5h 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•5h ago
I could test for me, I made a change that worked for me
BastiGame惄
BastiGame惄OP•5h 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•5h 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•5h 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•4h ago
I think I know the problem, I'll fix it
1Lucas1.apk
1Lucas1.apk•4h 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•4h 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•4h ago
No description
BastiGame惄
BastiGame惄OP•4h 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•4h ago
I will launch this when one of the source is finished inside the package It can be :hi:
Solution
BastiGame惄
BastiGamećƒ„ā€¢4h ago
Thank you šŸ™‚

Did you find this page helpful?