Hey everyone! I’m working on a Discord bot using Python and I’m trying to add some music features. I’m using Wavelink to connect to a Lavalink server, but I’m running into issues.
When I start my bot, I get this error:
An unexpected error occurred while connecting Node(identifier=FqC_saAyp5nuK2wL, uri=localhost:2333, status=NodeStatus.CONNECTING, players=0) to Lavalink: ""
Here’s the relevant part of my bot code:
@bot.event
async def setup_music_node():
await wavelink.Pool.connect(
client=bot,
nodes=[
wavelink.Node(
uri="127.0.0.1:2333",
password="mysecretpassword"
)
]
)
async def on_music_node_ready(node: wavelink.Node):
print(f'Music node {node.identifier} is up and running!')
And here’s my Lavalink config:
server:
port: 2333
address: 127.0.0.1
lavalink:
server:
password: "mysecretpassword"
sources:
youtube: true
soundcloud: true
logging:
level:
root: INFO
Any ideas why it’s not connecting? Thanks in advance for your help!
I’ve encountered similar issues when setting up Lavalink with Discord bots. One common oversight is ensuring the Lavalink server is actually running before attempting to connect your bot. Double-check that your Lavalink instance is up and listening on the specified port.
Another potential issue could be firewall settings. If you’re running the bot and Lavalink on different machines, make sure the appropriate ports are open.
Lastly, try adding a scheme to your URI. Instead of “127.0.0.1:2333”, use “http://127.0.0.1:2333”. This sometimes resolves connection problems.
If these don’t work, you might want to check your Lavalink server logs for any errors during startup or connection attempts. They often provide more detailed information about what’s going wrong.
hey man, try using ‘ws://127.0.0.1:2333’ for the uri instead. lavalink uses websockets, so the ‘ws://’ prefix is important. also, double check ur firewall settings and make sure the port is open. good luck with ur bot!
I’ve been there, mate. Connecting Discord bots to Lavalink can be a real pain sometimes. From what I can see, your setup looks mostly correct, but there’s one thing you might want to try.
In your Python code, change the URI to include the ‘ws://’ protocol. So instead of ‘127.0.0.1:2333’, use ‘ws://127.0.0.1:2333’. Lavalink uses WebSocket connections, and explicitly specifying this can sometimes solve connection issues.
Also, make sure your Lavalink server is actually running before you start your bot. I’ve embarrassingly spent hours debugging before realizing I forgot to start the Lavalink server!
If that doesn’t work, try running both your bot and Lavalink server with more verbose logging. This can often reveal issues that aren’t immediately apparent. Good luck with your project!