Lavalink&Bot saying it's playing, but Bot wont join the channel

Hi, Im new to moonlink.js and have worked with erela.js years ago, so i want to make a Radio Bot that should start all streams automatically when the Bot gets started. The Lavalink recieves the requests, and the bot also answers that it started playing, but the bot wont connect to my voice channel. I've included all Intents, the Bot has Administrator Perms, i've already tried to fetch the guild/all channels on startup but still it's refusing to connect to the Voice Channel. If i run the same command manually it works fine. I think it has something to with the cache but idk. Maybe someone can help! I do not recieve any errors in my bot/lavalink. The code is here:
async function start_stream(guild, textchannel, voicechannel) {

let query = "https://www.youtube.com/watch?v=zQshJwIahZM"
let player = client.moon.players.create({
guildId: guild,
voiceChannel: voicechannel,
textChannel: textchannel,
autoPlay: true
});
let channel = client.guilds.cache.get(guild).channels.cache.get(textchannel)
console.log(player)
if (!player.connected) {
// Connecting to the voice channel if not already connected
player.connect({
setDeaf: true,
setMute: false
});
}
let res = await client.moon.search(query);

if (res.loadType === "loadfailed") {
// Responding with an error message if loading fails
return channel.send({
content: `:x: Load failed - the system is not cooperating.`
});
} else if (res.loadType === "empty") {
// Responding with a message if the search returns no results
return channel.send({
content: `:x: No matches found!`
});
}



if (!player.playing) {
// Starting playback if not already playing
player.play();
}


}
async function start_stream(guild, textchannel, voicechannel) {

let query = "https://www.youtube.com/watch?v=zQshJwIahZM"
let player = client.moon.players.create({
guildId: guild,
voiceChannel: voicechannel,
textChannel: textchannel,
autoPlay: true
});
let channel = client.guilds.cache.get(guild).channels.cache.get(textchannel)
console.log(player)
if (!player.connected) {
// Connecting to the voice channel if not already connected
player.connect({
setDeaf: true,
setMute: false
});
}
let res = await client.moon.search(query);

if (res.loadType === "loadfailed") {
// Responding with an error message if loading fails
return channel.send({
content: `:x: Load failed - the system is not cooperating.`
});
} else if (res.loadType === "empty") {
// Responding with a message if the search returns no results
return channel.send({
content: `:x: No matches found!`
});
}



if (!player.playing) {
// Starting playback if not already playing
player.play();
}


}
Thanks for your Time & Merry Christmas
36 Replies
1Lucas1.apk
1Lucas1.apk•15mo ago
Hello, I just have one question, how did you put the spayload function in the main constructor? client.moon = new MoonlinkManager( [], {}, Spayload ) I forgot, merry Christmas to you too :hi:
adverse-sapphire
adverse-sapphireOP•15mo ago
🙂 Will Send you tomorrow When i am on My Computer. But i Think Its just default
1Lucas1.apk
1Lucas1.apk•15mo ago
Do you use discord.js V14?
adverse-sapphire
adverse-sapphireOP•15mo ago
Yes
1Lucas1.apk
1Lucas1.apk•15mo ago
Did you place the intents in these stores?
adverse-sapphire
adverse-sapphireOP•15mo ago
Yea
1Lucas1.apk
1Lucas1.apk•15mo ago
In the Spayload function, could you put a console.log of the two parameters?
adverse-sapphire
adverse-sapphireOP•15mo ago
Another question, i want to do a 24/7 stream and I know that the stream will disconnect at one time because of discord. Do you know how I can detect this and reconnect automatically and how I can resume all lavalonk streams that have not been finished on reboot?
1Lucas1.apk
1Lucas1.apk•15mo ago
discord.js has an event called voiceStateUpdate You can use it to identify if you have been disconnected from a call For example: In reality, I think you can do it using the package instead of the event In moonlink there is an event called playerDisconnected playerDisconnect: (player: MoonlinkPlayer) => void; Disconnect* It will output the player that was disconnected, you can reuse the class to connect in the call and restart client.moon.on("playerDisconnect", async(player) => { player.connect() await player.restart() }) I think this is the only thing that works Restarting will make moonlink send the player information again and continue where it left off
adverse-sapphire
adverse-sapphireOP•15mo ago
Okay, but will this work also with radio streams? Like it does not has an ending point
MEE6
MEE6•15mo ago
GG @Fireball, you just advanced to level 1!
1Lucas1.apk
1Lucas1.apk•15mo ago
Yes, in a stream it goes to the position where the stream is I think, because I never tried it much on stream, I don't know if there's a way to go back 😦 I don't think so, because generally stream doesn't have a limit so the position is negative It will stay where it is currently playing on the stream
adverse-sapphire
adverse-sapphireOP•15mo ago
It’s not needed to go back It only needs to restart the stream Idc if it not continues
1Lucas1.apk
1Lucas1.apk•15mo ago
I'll give it a test
adverse-sapphire
adverse-sapphireOP•15mo ago
Thanks
1Lucas1.apk
1Lucas1.apk•15mo ago
Did a question manage to make it work?
adverse-sapphire
adverse-sapphireOP•15mo ago
?
1Lucas1.apk
1Lucas1.apk•15mo ago
Fix the bot thing that couldn't connect...
adverse-sapphire
adverse-sapphireOP•15mo ago
Yea I got it by installing the newest version and doing some other stuff with fetching all guilds/channels I think it couldn’t start the stream, bc it couldn’t find the channel as nothing was in the bots cache, so I’ve done a fetch function and a delay for the stream start new error when playing a spotify playlist: SyntaxError: Unterminated string in JSON at position 1200 at JSON.parse (<anonymous>) at MoonlinkNode.message (C:\Users\paul0\Desktop\lavabeats\node_modules\moonlink.js\dist\src@Entities\MoonlinkNode.js:178:28) at WebSocket.emit (node:events:513:28) at Socket.<anonymous> (C:\Users\paul0\Desktop\lavabeats\node_modules\moonlink.js\dist\src@Services\PerforCWebsocket.js:124:30) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:297:9) at Readable.push (node:internal/streams/readable:234:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) SyntaxError: Unexpected token 'w', "tworkUrl":n"... is not valid JSON at JSON.parse (<anonymous>) at MoonlinkNode.message (C:\Users\paul0\Desktop\lavabeats\node_modules\moonlink.js\dist\src@Entities\MoonlinkNode.js:178:28) at WebSocket.emit (node:events:513:28) at Socket.<anonymous> (C:\Users\paul0\Desktop\lavabeats\node_modules\moonlink.js\dist\src@Services\PerforCWebsocket.js:124:30) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:283:9) at Readable.unshift (node:internal/streams/readable:239:10) at Socket.<anonymous> (C:\Users\paul0\Desktop\lavabeats\node_modules\moonlink.js\dist\src@Services\PerforCWebsocket.js:148:33) at Socket.emit (node:events:513:28) -> after that, the music plays succesfully, but no events are triggered AND new requests wont be accepted with error "No Lavalink is connected" i have the lavasrc plugin installed on my lavalink, but nothing on my bot side & when using player.skip() i get
adverse-sapphire
adverse-sapphireOP•15mo ago
1Lucas1.apk
1Lucas1.apk•15mo ago
It appears to be a Websocket code error I will change to ws which is more stable
adverse-sapphire
adverse-sapphireOP•15mo ago
okay, but like do i need any plugin for spotify on the bot code site, or just on the lavalink?
1Lucas1.apk
1Lucas1.apk•15mo ago
You just need LavaSrc and it will work
adverse-sapphire
adverse-sapphireOP•15mo ago
ok perfect @1Lucas1.apk are you here
MEE6
MEE6•15mo ago
GG @Fireball, you just advanced to level 2!
adverse-sapphire
adverse-sapphireOP•15mo ago
i have a question so i have an array with youtube song urls, but somehow i cant add them to the queue, as it says i need to add it as a string/array
let urlsArray = [
'https://www.youtube.com/watch?v=ZQXcilqm7-E',
'https://www.youtube.com/watch?v=SlOSq-d0Pj4'
]
let res = await client.moon.search(urlsArray);
let urlsArray = [
'https://www.youtube.com/watch?v=ZQXcilqm7-E',
'https://www.youtube.com/watch?v=SlOSq-d0Pj4'
]
let res = await client.moon.search(urlsArray);
1Lucas1.apk
1Lucas1.apk•15mo ago
Hello Moonlink doesn't support url arrays, but I can support it as soon as I figure out what I did wrong in websocket
adverse-sapphire
adverse-sapphireOP•15mo ago
ok but if i do this
fav.map(async song => {
console.log(song.url);
let res = await client.moon.search(song.url);

if (res.loadType === "loadfailed" || res.loadType === "empty") {
fail++;
}

if (res.loadType === "playlist") {
for (const track of res.tracks) {
player.queue.add(track);
}
} else {
player.queue.add(res.tracks[0]);
}

if (!player.playing) {
player.play();
}
});
fav.map(async song => {
console.log(song.url);
let res = await client.moon.search(song.url);

if (res.loadType === "loadfailed" || res.loadType === "empty") {
fail++;
}

if (res.loadType === "playlist") {
for (const track of res.tracks) {
player.queue.add(track);
}
} else {
player.queue.add(res.tracks[0]);
}

if (!player.playing) {
player.play();
}
});
it still wont play the song
1Lucas1.apk
1Lucas1.apk•15mo ago
I can't modify it to support array, because search already works with 2 types, object with sorce and request information and string, this causes conflict to support array You will have to use this code you made 🥺 using map A thousand apologies
adverse-sapphire
adverse-sapphireOP•15mo ago
no problem
let player = client.moon.players.get(interaction.guild.id);
let position = player.current.position
let player = client.moon.players.get(interaction.guild.id);
let position = player.current.position
returns 0 is that right? i need the already played duration, like how many seconds have already been played, is that the right function or does that give me the status of the queue or some shit
1Lucas1.apk
1Lucas1.apk•15mo ago
Hello again, tomorrow I will fix this error, I apologize @Fireball I finished publishing a new version correcting the position
1Lucas1.apk
1Lucas1.apk•15mo ago
GitHub
Release v3.0.8 · Ecliptia/moonlink.js
What's Changed Fixed track position error not leaving 0 by @1Lucas1apk in #53 Full Changelog: v3.0.5...v3.0.8
adverse-sapphire
adverse-sapphireOP•15mo ago
Hi, sorry to annoy you again, but i think i found another bug
console.log(player.previous)
await player.queue.add(player.previous, 0)
console.log(player.previous)
await player.queue.add(player.previous, 0)
so what i am trying to do is a /back or /previous command, where you can play the last title again. but currently player.previous returns the current playing song and not the last played song this is still not right. it sometimes returns the number in negative and sometimes in positive, also for me it always starts at 0:30minutes sometimes the duration is -0:30 and sometimes its 0:30
adverse-sapphire
adverse-sapphireOP•15mo ago
https://i.imgur.com/E5VB65K.png soon its finished :D green=working, red=notworking, yellow:sometimes working
Imgur
1Lucas1.apk
1Lucas1.apk•15mo ago
Thank you for reporting the errors, I will analyze the internal codes and update It's getting really cool I think I'm going to modify the position for two parameters, realtimeposition and position, brought by lavalink
adverse-sapphire
adverse-sapphireOP•15mo ago
yeah

Did you find this page helpful?