Skip to content

Commit

Permalink
fix: destroy function
Browse files Browse the repository at this point in the history
This commit fixes destroy function which would end up killing all Players.
  • Loading branch information
ThePedroo committed Nov 27, 2023
1 parent 918e121 commit 7baf1ab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Player {
* @throws {None}
*/
destroy() {
Nodes[this.node].players[this.guildId] = null
Players[this.guildId] = null

this.makeRequest(`/sessions/${Nodes[this.node].sessionId}/players/${this.guildId}`, {
method: 'DELETE'
Expand Down
7 changes: 5 additions & 2 deletions src/events/track/trackEnds.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ function trackEnds(Event, payload, node, config, Nodes, Players) {

const player = Players[payload.guildId]

if (!player)
return console.log(`[FastLink] Received ${name} from ${node} but no player was found`)
if (!player) {
console.log(`[FastLink] Received ${name} from ${node} but no player was found`)

return Players
}

if (name != 'trackException' && config.queue && ['finished', 'loadFailed'].includes(payload.reason)) {
player.queue.shift()
Expand Down
6 changes: 5 additions & 1 deletion src/events/track/trackStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ function trackStart(Event, payload, node, config, Nodes, Players) {

const player = Players[payload.guildId]

if (!player) return console.log(`[FastLink] Received TrackStartEvent from ${node} but no player was found`)
if (!player) {
console.log(`[FastLink] Received TrackStartEvent from ${node} but no player was found`)

return Players
}

if (!config.queue) player.track = payload.track
player.playing = true
Expand Down
6 changes: 5 additions & 1 deletion src/events/track/websocketClosed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function websocketClosed(Event, payload, node, Nodes, Players) {
Event.emit('debug', `[FastLink] ${node} has received a WebsocketClosed`)

if (!Players[payload.guildId]) return console.log(`[FastLink] Received WebsocketClosed from ${node} but no player was found`)
if (!Players[payload.guildId]) {
console.log(`[FastLink] Received WebsocketClosed from ${node} but no player was found`)

return Players
}

delete Players[payload.guildId]

Expand Down

0 comments on commit 7baf1ab

Please sign in to comment.