Manager
Automata's Manager is the main hub for interacting with Lavalink like the iDROID that assists Snake in managing missions and communication in Metal Gear Solid V.
Constructor
new Manager(options: AutomataOptions)
Parameter (AutomataOptions) | Type | Description |
---|---|---|
nodes | Nodes | The map of nodes. |
defaultPlatform | String | The default platform used by the manager to fetch songs. Default platform is Deezer. |
reconnectTimeout | Number | The time the manager will wait before trying to reconnect to a node. |
reconnectTries | Number | The amount of times the player will try to reconnect to a node. |
resumeStatus | Boolean | Used to enable / disable resuming. |
resumeTimeout | Number | The time the manager will wait before trying to resume the previous session. |
Properties
_.nodes
Where the nodes are initially saved.
Type: Node
.nodes
A map of the nodes.
Type: Map<string, Node>
.players
A map of the players.
Type: Map<string, Player>
.options
Where the options are initially stored in the constructor.
Type: AutomataOptions
Methods
.init(client)
This method initializes the manager.
Parameter | Type | Description |
---|---|---|
client | Client | The Discord.js Client class. |
Returns: void
Exemple
/** Must be present in your bot's ready.js. */
<Automata>.init(<client>)
.addNode(node)
Adds a new node to the node pool and establishes a connection to it.
Parameter | Type | Description |
---|---|---|
node | NodeOptions | The options need for Automata to establish a connection to the node. |
Returns: Node
Exemple
<Manager>.addNode({ name: 'ATM_Node01', host: 'localhost', port: 3000, password: 'Capybara' })
.removeNode(identifier)
Removes the specified node from the node pool and disconnects from it.
Parameter | Type | Description |
---|---|---|
identifier | String | The name of the node that you want to remove. |
Returns: void
Exemple
<Manager>.removeNode('ATM_Node01')
.leastUsedNodes
Returns the least used node.
Returns: Node
Exemple
<Manager>.leastUsedNodes()
.getNode(identifier)
Retrieves the specified node.
Parameter | Type | Description |
---|---|---|
identifier | String | The name of the node that you want to retrieve info for. |
Returns: Node | Node
Exemple
<Manager>.getNode('ATM_Node01');
.create(options)
Creates a player or returns one if it already exists.
Parameter | Type | Description |
---|---|---|
options | ConnectionOptions | The options needed to create a player. |
Exemple
const player = client.manager.create({
guildId: interaction.guild.id,
voiceChannel: interaction.member.voice.channelId,
textChannel: interaction.channelId,
deaf: true,
});
.resolve({ query, requester })
Resolves the provided query.
Parameter | Type | Description |
---|---|---|
query | String | The name / URL of the song you'd like to queue. |
requester | Object | The requester of the song (always a Discord.js User) |
Returns: Promise
Exemple
const res = await client.manager.resolve({
query: 'never gonna give you up (or some other song) / URL to a song,'
requester: interaction.user,
});
.getLavalinkStats()
Gets information regarding about the node's players, uptime, memory etc.
Returns: NodeStats
Exemple:
<Manager>.getLavalinkStats();
Events
nodeConnect
Emitted when Automata successfully connects to a Lavalink node.
Parameter | Type |
---|---|
node | Node |
nodeDisconnect
Emitted when Automata loses the connection to a Lavalink node.
Parameter | Type |
---|---|
node | Node |
nodeReconnect
Emitted when Automata successfully reconnects to a Lavalink node.
Parameter | Type |
---|---|
node | Node |
nodeError
Emitted when a Node related error occurs.
trackStart
Emitted when a player starts playing a new track.
trackEnd
Emitted when a player finishes playing a track.
trackStuck
Emitted when a track gets stuck while it is playing.
queueEnd
Emitted when the player's queue has finished.
Parameter | Type |
---|---|
player | Player |
playerUpdate
Emitted when the player gets updated.
Parameter | Type |
---|---|
player | Player |
playerDestroy
Emitted when a player gets destroyed.
Parameter | Type |
---|---|
player | Player |
socketClose
Emitted when the connection between the WebSocket and Discord voice servers drops.