-
Notifications
You must be signed in to change notification settings - Fork 1
Home
AquaLink is a lightweight and efficient Lavalink wrapper designed for performance and stability. It allows developers to integrate Lavalink into their Discord bots with minimal dependencies. AquaLink handles voice connections, track playback, and queue management with ease.
- 🚀 Minimal Dependencies – AquaLink is designed to be lightweight and fast.
- 🎵 Built-in Queue Management – No need for external queue handling.
- 🔄 Auto-Reconnect for Lavalink Nodes – Ensures a stable connection.
- 🔊 High-Quality Audio Streaming – Supports multiple formats and platforms.
- 🌍 Supports Multiple Lavalink Nodes – Load balancing for better performance.
- 🔥 Easy-to-Use API – Simple and intuitive commands for managing playback.
Before using AquaLink, ensure you have:
- Node.js installed (v16 or later recommended).
- Lavalink Server set up and running.
npm install aqualink
You also need to have a running Lavalink server:
- Download Lavalink from here.
- Install Java 17 or newer.
- Configure the
application.yml
file with your preferred settings. - Start the Lavalink server using:
java -jar Lavalink.jar
const { AquaLink } = require("aqualink");
const nodes = [
{
host: "127.0.0.1",
password: "yourpass",
port: 233,
secure: false,
name: "localhost"
}
];
const aqua = Aqua(client, nodes, {
defaultSearchPlatform: "ytsearch",
restVersion: "v4",
autoResume: false,
infiniteReconnects: true,
});
AquaLink requires voice state updates to maintain connections. Ensure you handle these events properly:
client.on("raw", (d) => {
if (![GatewayDispatchEvents.VoiceStateUpdate, GatewayDispatchEvents.VoiceServerUpdate].includes(d.t)) return;
client.aqua.updateVoiceState(d);
});
async function connectToChannel(guildId, channelId) {
const player = client.aqua.players.get(interaction.guildId);
player.connect(channelId);
}
async function playTrack(guildId, track) {
let player = client.aqua.players.get(interaction.guildId);
if (!player) {
player = client.aqua.createConnection({
defaultVolume: 65,
guildId: interaction.guildId,
voiceChannel: interaction.member.voice.channelId,
textChannel: interaction.channelId,
deaf: true
});
}
player.play(track);
}
Example of Searching for a Track Using Lavalink
async function searchAndPlay(guildId, query) {
const resolve = await client.aqua.resolve({
query,
requester: interaction.member, // optional!
source: "scsearch"
});
if (!results.tracks.length) return console.log("No results found.");
const track = results.tracks[0];
await player.queue.add(track)
if (!player.playing && !player.paused && player.queue.size > 0) {
player.play();
}
}
async function pausePlayback(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) player.pause(true);
}
async function resumePlayback(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) player.pause(false);
}
async function skipTrack(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) player.stop();
}
async function stopPlayback(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) player.stop();
}
async function disconnectPlayer(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) player.destroy();
}
AquaLink provides a built-in queue manager for handling track queues.
async function addToQueue(guildId, track) {
const player = client.aqua.players.get(interaction.guildId);
if (!player.queue) player.queue = [];
player.queue.push(track);
if (!player.playing) playTrack(guildId, player.queue.shift());
}
async function viewQueue(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (!player || !player.queue.length) return console.log("The queue is empty.");
console.log("Current Queue:");
player.queue.forEach((track, index) => {
console.log(`${index + 1}. ${track.info.title}`);
});
}
async function loopTrack(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (!player) return;
player.queue.unshift(player.queue[player.queue.length - 1]);
}
AquaLink provides event listeners to monitor and manage playback.
client.aqua.on("trackStart", (player, track) => {
console.log(`Now playing: ${track.info.title}`);
});
client.aqua.on("trackEnd", (player, track) => {
console.log(`Finished playing: ${track.info.title}`);
if (player.queue.length > 0) {
player.play(player.queue.shift());
}
});
client.aqua.on("trackError", (player, track, error) => {
console.error(`Error playing ${track.info.title}: ${error.message}`);
});
To ensure your bot properly disconnects and cleans up resources, use the following:
async function cleanup(guildId) {
const player = client.aqua.players.get(interaction.guildId);
if (player) {
player.stop();
player.destroy();
}
}
- Ensure the Lavalink server is running and accessible.
- Verify the Lavalink password and port are correct in your code.
- Ensure your bot has the correct permissions (
CONNECT
andSPEAK
).
- The bot may be idle for too long. Consider implementing an inactivity timeout.
- Lavalink may be crashing—check your Lavalink logs.
- Check your server’s CPU and memory usage. Lavalink requires adequate resources.
- If hosting Lavalink remotely, ensure the network connection is stable.
AquaLink is used in various Discord music bots, including:
- 🎵 Chippy Music – A high-quality music bot powered by AquaLink.
- 🎵 Kenium - An Open Source music bot
If you are using AquaLink for your bot, feel free to submit a PR to add it to this list!
AquaLink provides a simple yet powerful way to integrate Lavalink with Discord bots. With built-in queue management, efficient resource handling, and easy-to-use methods, it makes audio playback seamless.
For more information, visit the GitHub repository.