TypeError: Cannot read properties of undefined (reading 'rest')

I get this error when i try to search for a song, heres hows my code is laid out:
// custom client for discord.js v14
class CustomClient extends Client {
constructor(options) {
super(options.clientOptions);
this.commands = new Collection();
this.utils = new Utils(this);
const payloadSender = (guild, payload) => {
this.guilds.cache.get(guild).shard.send(JSON.parse(payload))
};

this.manager = new MoonlinkManager(nodes, { spotify: JSON.parse(process.env.spotify) }, payloadSender);
}
... rest isnt important

// discord.js ready event
this.client.manager.init(this.client.user.id)

// discord.js raw event
this.client.manager.packetUpdate(data)

// moonlink.js nodeCreate event (which does get logged)
console.log(`New lavalink node connected: ${node.identifier}`)

// play command:
const player = client.manager.players.create({
guildId: interaction.guildId,
voiceChannel: channel.id,
textChannel: interaction.channelId
})

if(!player.connected) player.connect({
setMute: false,
setDeaf: true
})

client.manager.search({ query: query })
// custom client for discord.js v14
class CustomClient extends Client {
constructor(options) {
super(options.clientOptions);
this.commands = new Collection();
this.utils = new Utils(this);
const payloadSender = (guild, payload) => {
this.guilds.cache.get(guild).shard.send(JSON.parse(payload))
};

this.manager = new MoonlinkManager(nodes, { spotify: JSON.parse(process.env.spotify) }, payloadSender);
}
... rest isnt important

// discord.js ready event
this.client.manager.init(this.client.user.id)

// discord.js raw event
this.client.manager.packetUpdate(data)

// moonlink.js nodeCreate event (which does get logged)
console.log(`New lavalink node connected: ${node.identifier}`)

// play command:
const player = client.manager.players.create({
guildId: interaction.guildId,
voiceChannel: channel.id,
textChannel: interaction.channelId
})

if(!player.connected) player.connect({
setMute: false,
setDeaf: true
})

client.manager.search({ query: query })
the error is this.rest = this.node.rest; ^ TypeError: Cannot read properties of undefined (reading 'rest') and i know the lavalink gets the connection
48 Replies
1Lucas1.apk
1Lucas1.apk2y ago
Does it appear in the console that the node has been connected?
rare-sapphire
rare-sapphireOP2y ago
yes it does aswell as the lavalink logs
MEE6
MEE62y ago
GG @steven, you just advanced to level 1!
1Lucas1.apk
1Lucas1.apk2y ago
Could you send me a screenshot of the complete log?
rare-sapphire
rare-sapphireOP2y ago
also worth to mention that the lavalink is running on local host the error log?
1Lucas1.apk
1Lucas1.apk2y ago
Yeah
rare-sapphire
rare-sapphireOP2y ago
1Lucas1.apk
1Lucas1.apk2y ago
What is the version of nodejs and the version of moonlink.js
rare-sapphire
rare-sapphireOP2y ago
node is v18.17.0 moonlink is 2.11.76 discord.js is 14.13.0
1Lucas1.apk
1Lucas1.apk2y ago
Could you update moonlink.js to v2.13.4?
rare-sapphire
rare-sapphireOP2y ago
yeah let me try same issue
1Lucas1.apk
1Lucas1.apk2y ago
What is the lavalink version? I have to ask questions until I find the root of the problem 🤭
rare-sapphire
rare-sapphireOP2y ago
your good just updated the console log New lavalink node connected: NA-01 running 4.0.0-beta.4
1Lucas1.apk
1Lucas1.apk2y ago
Do you have access to node_modules? If so, you could enter the file "/node_modules/moonlink.js/dist/src/MoonlinkPlayer.js" on line 65 and place console.log(node) To see what returns from the node
rare-sapphire
rare-sapphireOP2y ago
ReferenceError: node is not defined i tried this.node but it returned undefined
1Lucas1.apk
1Lucas1.apk2y ago
You can now put console.log(this.data)
rare-sapphire
rare-sapphireOP2y ago
{
guildId: '...',
textChannel: '...',
voiceChannel: '...',
volume: 80,
playing: false,
connected: false,
paused: false,
shuffled: false,
loop: null,
autoPlay: false,
node: 'localhost'
}
{
guildId: '...',
textChannel: '...',
voiceChannel: '...',
volume: 80,
playing: false,
connected: false,
paused: false,
shuffled: false,
loop: null,
autoPlay: false,
node: 'localhost'
}
i blocked out the ids my self but they are valid
1Lucas1.apk
1Lucas1.apk2y ago
Is the problem really because it is localhost? Apparently yes lol
rare-sapphire
rare-sapphireOP2y ago
no because i tried a hosted node lemme try again a hosted one do u have a v4 hosted one? that i can test really quickly
1Lucas1.apk
1Lucas1.apk2y ago
console.log(this.manager.nodes.values())
rare-sapphire
rare-sapphireOP2y ago
console.log(this.manager.nodes.values()) ^ TypeError: Cannot read properties of undefined (reading 'nodes')
MEE6
MEE62y ago
GG @steven, you just advanced to level 2!
1Lucas1.apk
1Lucas1.apk2y ago
console.log(manager.nodes.values()) this.manager is only assigned at the very bottom Do you use identifier? On node
rare-sapphire
rare-sapphireOP2y ago
yes also i just put it on a hosted one v4 itstill has the same iossue
1Lucas1.apk
1Lucas1.apk2y ago
If you use this, it could be one of the factors in the problem, as I noticed that it uses the host name instead of the identifier if it has
rare-sapphire
rare-sapphireOP2y ago
[Map Iterator] {
<ref *1> MoonlinkNode {
manager: MoonlinkManager {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_nodes: [Array],
_sPayload: [Function: payloadSender],
initiated: true,
options: [Object],
nodes: [Map],
spotify: [Spotify],
clientId: '...',
version: '2.13.04',
map: [Map],
[Symbol(kCapture)]: false
},
host: '...',
port: 2501,
password: '...',
identifier: 'NA-01',
secure: null,
version: '4.0.0-beta.4',
options: {
spotify: [Object],
sortNode: 'players',
custom: {},
clientName: 'Moonlink/2.13.04'
},
sPayload: undefined,
socketUri: 'ws://...:2501/v4/websocket',
restUri: 'http://...:2501/v4/',
rest: MoonlinkRest {
manager: [MoonlinkManager],
sessionId: '71msasa1knqswdh2',
node: [Circular *1],
url: 'http://...:2501/v4/'
},
resume: null,
resumed: false,
sessionId: '71msasa1knqswdh2',
isConnected: true,
ws: MoonlinkWebsocket {
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
options: [Object],
socket: [ClientRequest],
agent: [Object],
url: [URL],
[Symbol(kCapture)]: false
},
stats: {
frameStats: null,
players: 0,
playingPlayers: 0,
uptime: 51375,
memory: [Object],
cpu: [Object]
},
retryTime: 30000,
reconnectAtattempts: 0,
reconnectTimeout: undefined,
resumeKey: undefined,
resumeStatus: true,
resumeTimeout: 30000,
calls: 0,
retryAmount: 5,
sendWs: undefined,
node: {
host: '...',
port: 2501,
identifier: 'NA-01',
secure: false,
password: '...'
},
map: Map(2) { 'sessionId' => '71msasa1knqswdh2', 'players' => [Object] },
db: MoonlinkDatabase { data: {}, id: '...' }
}
}
[Map Iterator] {
<ref *1> MoonlinkNode {
manager: MoonlinkManager {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_nodes: [Array],
_sPayload: [Function: payloadSender],
initiated: true,
options: [Object],
nodes: [Map],
spotify: [Spotify],
clientId: '...',
version: '2.13.04',
map: [Map],
[Symbol(kCapture)]: false
},
host: '...',
port: 2501,
password: '...',
identifier: 'NA-01',
secure: null,
version: '4.0.0-beta.4',
options: {
spotify: [Object],
sortNode: 'players',
custom: {},
clientName: 'Moonlink/2.13.04'
},
sPayload: undefined,
socketUri: 'ws://...:2501/v4/websocket',
restUri: 'http://...:2501/v4/',
rest: MoonlinkRest {
manager: [MoonlinkManager],
sessionId: '71msasa1knqswdh2',
node: [Circular *1],
url: 'http://...:2501/v4/'
},
resume: null,
resumed: false,
sessionId: '71msasa1knqswdh2',
isConnected: true,
ws: MoonlinkWebsocket {
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
options: [Object],
socket: [ClientRequest],
agent: [Object],
url: [URL],
[Symbol(kCapture)]: false
},
stats: {
frameStats: null,
players: 0,
playingPlayers: 0,
uptime: 51375,
memory: [Object],
cpu: [Object]
},
retryTime: 30000,
reconnectAtattempts: 0,
reconnectTimeout: undefined,
resumeKey: undefined,
resumeStatus: true,
resumeTimeout: 30000,
calls: 0,
retryAmount: 5,
sendWs: undefined,
node: {
host: '...',
port: 2501,
identifier: 'NA-01',
secure: false,
password: '...'
},
map: Map(2) { 'sessionId' => '71msasa1knqswdh2', 'players' => [Object] },
db: MoonlinkDatabase { data: {}, id: '...' }
}
}
1Lucas1.apk
1Lucas1.apk2y ago
You knew Wait a little bit
rare-sapphire
rare-sapphireOP2y ago
? okay without an identifier it works @1Lucas1.apk
1Lucas1.apk
1Lucas1.apk2y ago
Could you do a test for me?, Install the new version I just published and try again to use the player @steven
rare-sapphire
rare-sapphireOP2y ago
with or without an identifier?
1Lucas1.apk
1Lucas1.apk2y ago
With
rare-sapphire
rare-sapphireOP2y ago
works bro thanks :D
1Lucas1.apk
1Lucas1.apk2y ago
Thanks for reporting the issue and have a great day 🙂
rare-sapphire
rare-sapphireOP2y ago
you aswell @1Lucas1.apk also how can i destroy all players when the bot shuts off without turning off lavalink? other modules do it
1Lucas1.apk
1Lucas1.apk2y ago
I'll have to do this inside the package I'll have to do this inside the package
rare-sapphire
rare-sapphireOP2y ago
oh ok also my playlist wont load @1Lucas1.apk C:\Users\clap\Desktop\gr$pe v3\node_modules\moonlink.js\dist\src@Sources\Spotify.js:46 const items = initialPage.items || []; ^ TypeError: Cannot read properties of undefined (reading 'items') im heavily dependent on spotify
cloudy-cyan
cloudy-cyan2y ago
playerlist url ? 🧐 Because I can't trigger your problem
MEE6
MEE62y ago
GG @steven, you just advanced to level 3!
rare-sapphire
rare-sapphireOP2y ago
oh its cuz its private?
cloudy-cyan
cloudy-cyan2y ago
yes
rare-sapphire
rare-sapphireOP2y ago
okay i just tried it again hile its not and its taking forever no way to speed it up?
cloudy-cyan
cloudy-cyan2y ago
no
rare-sapphire
rare-sapphireOP2y ago
im looking at the lavalink logs and its only at the 11th song and not going anymore how come other modules instantly load it lol highly considering going to lavalink-client i mean it kinda seems like this module is in very early stages of development tbh
cloudy-cyan
cloudy-cyan2y ago
🤔 he leave :(((
1Lucas1.apk
1Lucas1.apk2y ago
F I just found out that for me to withdraw funds from GitHub sponsors, I need a minimum of $5 You'll be stuck there until you get it lol I'm going to try to make a parameter so that when the bot has been disconnected, when it reconnects, it stops all players
cloudy-cyan
cloudy-cyan2y ago
XDD
MEE6
MEE62y ago
GG @aaaaa, you just advanced to level 6!

Did you find this page helpful?