NUEVO 📢 Ahorra hasta un 30% en tu primer mes, ¡oferta por tiempo limitado!

How to connect your Discord bot to Lavalink

Discord bot hostingUpdated Oct 6, 20263 min read

Your bot needs three values from your Lavalink node: the host, the port and the password. See How to host a Lavalink music node to find them.

What every client asks for

SettingValue
Hostthe address before the colon, for example 136.243.0.51
Portthe number after the colon
Passwordthe password in application.yml
Secure (HTTPS)off, the node uses plain http and ws

Keep the password out of your code: put it in a .env file or a settings file you do not publish.

Node.js with Shoukaku

```js const { Shoukaku, Connectors } = require('shoukaku');

const nodes = [{ name: 'main', url: ${process.env.LAVALINK_HOST}:${process.env.LAVALINK_PORT}, auth: process.env.LAVALINK_PASSWORD, secure: false, }];

const shoukaku = new Shoukaku(new Connectors.DiscordJS(client), nodes); shoukaku.on('ready', (name) => console.log(Lavalink node ${name} connected)); shoukaku.on('error', (name, error) => console.error(Lavalink node ${name}, error)); ```

Create it after your client object exists. The library's documentation shows how to join a voice channel and play a track.

```python import os import discord import wavelink from discord.ext import commands

bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())

@bot.event async def on_ready(): node = wavelink.Node( uri=f"http://{os.environ['LAVALINK_HOST']}:{os.environ['LAVALINK_PORT']}", password=os.environ["LAVALINK_PASSWORD"], ) await wavelink.Pool.connect(nodes=[node], client=bot) print("Lavalink connected") ```

It does not connect

  • Connection refused or timed out: the host or port is wrong, or the node is stopped. Check Overview and start it.
  • 401 or unauthorized: the password does not match application.yml.
  • It connects, then plays nothing: the bot needs the Connect and Speak permissions in the voice channel, and the node needs a source that can play what you asked. See Discord music bot not playing: fixes.
  • Make sure your client matches the node's major version. A client built for Lavalink 3 does not work with a version 4 node.

CREA TU SERVIDOR DE JUEGOS
¿LISTO PARA EMPEZAR?

Ahorra hasta un 30% en tu nuevo servidor de juegos.
Rendimiento premium, activación instantánea y una fiabilidad inigualable al mejor precio.

NUESTROS ÚLTIMOS BLOGS