Skip to content

Commit a3158a8

Browse files
committed
add: getPlayer function
This commit adds the missing "getPlayer" function.
1 parent 63c8a43 commit a3158a8

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

index.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,32 @@ class Player {
483483
}
484484
}
485485

486+
/**
487+
* Retrieves the player for a given guild.
488+
*
489+
* @param guildId The guild to retrieve player from.
490+
* @param node The node to retrieve player from.
491+
*
492+
* @throws Error If no guildId is provided or if guildId is not a string.
493+
* @throws Error If no node is provided or if node is not a string.
494+
* @throws Error If player does not exist.
495+
*
496+
* @returns A Promise that resolves to the retrieved player data.
497+
*/
498+
function getPlayer(guildId, node) {
499+
if (!guildId) throw new Error('No guildId provided.')
500+
if (typeof guildId !== 'string') throw new Error('GuildId must be a string.')
501+
502+
if (!node) throw new Error('No node provided.')
503+
if (typeof node !== 'string') throw new Error('Node must be a string.')
504+
505+
if (!Players[guildId]) throw new Error('Player does not exist.')
506+
507+
if (!Nodes[node]) throw new Error('Node does not exist.')
508+
509+
return utils.makeNodeRequest(Nodes, node, `/v4/sessions/${Nodes[node].sessionId}/players/${guildId}`, { method: 'GET' })
510+
}
511+
486512
/**
487513
* Retrieves the players for a given node.
488514
*
@@ -678,7 +704,8 @@ export default {
678704
},
679705
player: {
680706
Player,
681-
getPlayers
707+
getPlayers,
708+
getPlayer
682709
},
683710
routerPlanner: {
684711
getRouterPlannerStatus,

0 commit comments

Comments
 (0)