A package for integrating Lavalink with Aoi.js to enable music streaming in Discord bots.
npm install aoijs.lavalink
The setup is used to initialize the bot client and configure the Lavalink music system. aoi.js is the main client framework, and aoijs.lavalink is an integration that allows you to connect to a Lavalink server to stream music.
const { AoiClient } = require('aoi.js');
const { Manager } = require('aoijs.lavalink'); // Importing the MusicClient for handling Lavalink integration.
const client = new AoiClient({ ... });
const voice = new Manager(client, {
nodes: [{
name: 'my lavalink node', // A custom name for the Lavalink node (can be any string).
host: 'yourdomain.com', // URL to your Lavalink node. Replace with your actual Lavalink server URL.
port: 0000, // Your lavalink server port.
auth: 'youshallnotpass', // Authentication password for the Lavalink node.
secure: false // Set to true if your Lavalink server uses SSL/TLS (HTTPS).
}],
maxQueueSize: 100, // Maximum number of tracks that can be queued for playback. (default is 100)
maxPlaylistSize: 100, // Maximum number of tracks that can be in a playlist. (default is 100)
searchEngine: 'ytsearch', // Default search engine. You can set this to 'ytsearch' or 'scsearch' or others. (default is ytsearch)
debug: false // Whether to enable debug logs for the music client. default is false. (default is false)
});
see here for more client options.
You can listen to various events such as when a track starts, when the player is paused, etc., and respond to them with custom code.
const voice = new Manager({ ... });
voice.<eventName>({ // The event type, e.g., when a track starts playing ('trackStart').
channel: '$channelId', // The ID of the channel where the event will trigger (can be dynamic or static).
code: `$songInfo[title]` // The action to take when the event is triggered. Here it will return the title of the song.
});
const voice = new Manager({ ... });
// Load custom music event handlers from a directory. 'false' disables debug logs.
voice.loadVoiceEvents('./voice/', false);
Example Event File (in /voice/trackStart.js
):
module.exports = [
{
channel: '$channelId', // The ID of the channel where the event will trigger (can be dynamic or static).
type: 'trackStart', // The event type, e.g., when a track starts playing ('trackStart').
code: `$songInfo[title]`, // The action to take when the event is triggered. Here it will return the title of the song.
},
];
- Reading Functions: Currently aoi.js reads
$
functions from bottom to top.