Access to client instance from player

Hey everyone, I'd like to know if there's a way to access the client object from the player. If not, I'd like to know if there's a way to get the actual channel (TextChannel object) from the player.textChannel attribute
55 Replies
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I didn't quite understand your question Do you want the channel attributes? Like client.channels.cache.get(id)?
inland-turquoise
inland-turquoiseOPβ€’14mo ago
yup but the thing is that i don't have accest to my client instance
const logger = require("../logger")

module.exports = {
name: "trackStart",
async execute(player, track) {
console.log(player)
}
}
const logger = require("../logger")

module.exports = {
name: "trackStart",
async execute(player, track) {
console.log(player)
}
}
I would need to pass the client but idk if possible
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
You can pass the client attributes through the handler that executes the commands Events* I got the word wrong
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Yeah i'll look into that I already do a separate event handling for moonlink
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I understood Moonlink does not export the client, because it may sometimes be a different client This can make very unnecessary code That will never be used
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Yeah I can understand that
MEE6
MEE6β€’14mo ago
GG @Xotak, you just advanced to level 1!
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I hope you can solve your problem, if you have any further questions, just come here to ask and I will try to help you resolve it. Have a great day πŸ™‚ You can also use get and set from the player, I forgot about them
player.set("textChannel", channel)
player.get("textChannel") // The saved class
player.set("textChannel", channel)
player.get("textChannel") // The saved class
The set and get are stored in the player's data, some isolated values ​​of the player's attributes, this may be useful for you
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Oh you can store more data than those ?
No description
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Yes ?eval a
Blobit - Moonlink.js
Blobit - Moonlink.jsβ€’14mo ago
a is not defined
a is not defined
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Nice, I tried to add a client attribute in the create but that didn't work. I'll try to set a client like that. Does it work that way ?
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Probably yes, because the Channel's attributes are still there Stay in sync with the DJs
inland-turquoise
inland-turquoiseOPβ€’14mo ago
So if i understood properly, the set method change the map propriety of the player object ?
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Almost that, the set assigns the values ​​to data which is an object And class inheritance is not lost So you can use it when using get
inland-turquoise
inland-turquoiseOPβ€’14mo ago
I just need to access to channel cache, if I add a key with client as the name and the client as a value and if I do a player.get("client") I would get the client object right ?
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I think it would work Yes, it works, this creates a reference to the value, instead of a copy
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Took a break but it looks like it's working. I just upgraded moonlink and I'm having an issue with the voiceRegion in PlayerManager
οΏ½~{"op":"stats","frameStats":null,"players":0,"playingPlayers":0,"uptime":825121,"memory":{"free":83847320,"used":172005224,"allocated":255852544,"reservable":1520435200},"cpu":{"cores":8,"systemLoad":0.016896760583972097,"lavalinkLoad":0.0015416666666666667}}
/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/PlayerManager.js:76
this.cache[guildId].voiceRegion = voiceRegion[1];
^

TypeError: Cannot read properties of null (reading '1')
at PlayerManager.attemptConnection (/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/PlayerManager.js:76:62)
at MoonlinkManager.packetUpdate (/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/MoonlinkManager.js:144:26)
at Client.<anonymous> (/home/user/yadb/bot.js:115:17)
at Client.emit (node:events:519:28)
at WebSocketManager.<anonymous> (/home/user/yadb/node_modules/discord.js/src/client/websocket/WebSocketManager.js:236:19)
at WebSocketManager.emit (/home/user/yadb/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/user/yadb/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/home/user/yadb/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.onMessage (/home/user/yadb/node_modules/@discordjs/ws/dist/index.js:988:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.6.1
οΏ½~{"op":"stats","frameStats":null,"players":0,"playingPlayers":0,"uptime":825121,"memory":{"free":83847320,"used":172005224,"allocated":255852544,"reservable":1520435200},"cpu":{"cores":8,"systemLoad":0.016896760583972097,"lavalinkLoad":0.0015416666666666667}}
/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/PlayerManager.js:76
this.cache[guildId].voiceRegion = voiceRegion[1];
^

TypeError: Cannot read properties of null (reading '1')
at PlayerManager.attemptConnection (/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/PlayerManager.js:76:62)
at MoonlinkManager.packetUpdate (/home/user/yadb/node_modules/moonlink.js/dist/src/@Managers/MoonlinkManager.js:144:26)
at Client.<anonymous> (/home/user/yadb/bot.js:115:17)
at Client.emit (node:events:519:28)
at WebSocketManager.<anonymous> (/home/user/yadb/node_modules/discord.js/src/client/websocket/WebSocketManager.js:236:19)
at WebSocketManager.emit (/home/user/yadb/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/user/yadb/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/home/user/yadb/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.onMessage (/home/user/yadb/node_modules/@discordjs/ws/dist/index.js:988:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.6.1
I logged the PlayersManager and looks like cacke is empty
<ref *1> PlayerManager {
_manager: <ref *2> MoonlinkManager {
_events: [Object: null prototype] {
nodeCreate: [Function (anonymous)],
trackStart: [Array]
},
_eventsCount: 2,
_maxListeners: undefined,
clientId: '715944203430920334',
_nodes: [ [Object] ],
_SPayload: [Function (anonymous)],
players: [Circular *1],
nodes: NodeManager {
initiated: true,
_manager: [Circular *2],
map: [Map]
},
version: '3.2.88',
options: {
clientName: '@Moonlink/3.2.88 (https://github.com/Ecliptia/moonlink.js)',
clientId: '715944203430920334'
},
initiated: true,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
cache: {},
voices: {}
}
<ref *1> PlayerManager {
_manager: <ref *2> MoonlinkManager {
_events: [Object: null prototype] {
nodeCreate: [Function (anonymous)],
trackStart: [Array]
},
_eventsCount: 2,
_maxListeners: undefined,
clientId: '715944203430920334',
_nodes: [ [Object] ],
_SPayload: [Function (anonymous)],
players: [Circular *1],
nodes: NodeManager {
initiated: true,
_manager: [Circular *2],
map: [Map]
},
version: '3.2.88',
options: {
clientName: '@Moonlink/3.2.88 (https://github.com/Ecliptia/moonlink.js)',
clientId: '715944203430920334'
},
initiated: true,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
cache: {},
voices: {}
}
Trying to look into it, seems like it's not related to sharding
MEE6
MEE6β€’14mo ago
GG @Xotak, you just advanced to level 2!
inland-turquoise
inland-turquoiseOPβ€’14mo ago
I'll open an issue on GH I'll look in the forums before Found nothing Issue #72 reinstalled moonlink didn't work
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Can you put a log in node_modules? Apologies for the delay
inland-turquoise
inland-turquoiseOPβ€’14mo ago
No worries Where should I put that log ? I don't have my PC rn, I'll do it tmr (I'm in UTC+1)
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
In moonlink.js/dist/src/@Managers/PlayerManager.js On line 76 Before her puts console.log(voiceRegion, this) To see what happens before issuing the error
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Okay I'll do that. Do you want me to update the issue afterwards or I post the output here ?
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
You can post here
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Okay
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
This may help to find the error, It's probably in the voiceRegion
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Nearly 11pm here, I'll go to sleep. I'll go back to it early in the morning so I should have an answer in a few hours
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Okay, no problem, I'll wait
inland-turquoise
inland-turquoiseOPβ€’14mo ago
I put your name in my README as a thanks for your help
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
You also helped me find a console.log that I didn't remember was there
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Oh right, the one that sends metrics about Lavalink ?
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Yes There was a console.log in Websocket, and I forgot to remove it when I was debugging the code
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Console.log, best friend when debugging I think I have a problem with queueing, but that's in my play command since I don't have that issue with the sample code. Also, it would be great if there was more info on what does the method does. I can help with that if needed
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Ho, but this might also help fix other bugs in the code It's normal for this to happen Each Dev sometimes has different syntax, this can cause hidden errors to occur in the code
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Yup And since I do handlers and stuff, sometimes it gets complicated That's why I opened this issue in the first place
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
The playerManager is responsible for managing player information, such as endpoints, issuing playerDisconnected, updating information for lavalink such as changing the voice channel And it is also what manages the player classes And there is also voiceRegion that I implemented in a version
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Welcome to Moonlink.js
a universe of songs...
MEE6
MEE6β€’14mo ago
GG @Xotak, you just advanced to level 3!
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
So far, the documentation is not very updated
inland-turquoise
inland-turquoiseOPβ€’14mo ago
That's why I proposed my help If you don't plan it to do now, don't hesitate to ping me if you need help (Says the person that doesn't even completed his own)
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I'm a little embarrassed to ask for help πŸ₯Ί
inland-turquoise
inland-turquoiseOPβ€’14mo ago
No it's completely fine I am asking myself for help too I saw on your GH that you study on your own, you don't have to know everything
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
I'm left speechless :shy: Well I try to do my best (documentation is not my thing)
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Me neither I just saw I didn't push the beginning of my docs
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
πŸ˜…
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Well, it's really time for me to get to sleep. I don't know how your docs work but if it's just editing the markdown files I'm down
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Have a great night, the moonlink docs have another doc that explains how it works https://docus.dev
Home
The best place to start your documentation.
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Bye see you tomorrow
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Before I publish, could you test the version to see if it is working correctly? npm uninstall moonlink.js && npm install https://github.com/Ecliptia/moonlink.js
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. Support Server: https://discord.gg/xQq2A8vku3 - GitHub ...
inland-turquoise
inland-turquoiseOPβ€’14mo ago
That's what I did before closing the issue It worked, and queue was fixed
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
Well, I understand, thank you very much for reporting I'll see if I didn't leave any console.log this time
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Thanks for the release. I'll update my package.json accordingly
1Lucas1.apk
1Lucas1.apkβ€’14mo ago
You're welcome, have a great day
inland-turquoise
inland-turquoiseOPβ€’14mo ago
Thanks, you too !

Did you find this page helpful?