Discord music bot failing to establish connection with local server

I’m working on a Python Discord music bot using the wavelink library. Everything functioned perfectly during my initial local tests. However, after I tried deploying it on Heroku (which didn’t succeed), my local setup has also stopped working.

The Error

I’m facing this connection error:

WEBSOCKET | Connection Failure:: Cannot connect to host 127.0.0.1:2333
ConnectionRefusedError: [WinError 1225] Remote computer rejected network connection

My Code Setup

Here’s the function for initializing nodes:

async def initialize_audio_nodes(self):
    await self.client.wait_until_ready()
    
    # Setting up the audio node connection
    await self.client.wavelink.initiate_node(host='127.0.0.1',
                                            port=2333,
                                            rest_uri='http://127.0.0.1:2333',
                                            password='mysecretpass',
                                            identifier='MAIN_NODE',
                                            region='us_west')

My config.yml looks like this:

server:
  port: 2333
  address: 0.0.0.0
lavalink:
  server:
    password: "mysecretpass"
    sources:
      youtube: true
      soundcloud: true
      bandcamp: true
    bufferDurationMs: 400
    playerUpdateInterval: 5
logging:
  level:
    root: INFO

I’m puzzled because the code hasn’t changed at all. Has anyone else experienced a similar issue?

UPDATE: Resolved it! Make sure to start the Lavalink server by running java -jar Lavalink.jar in your terminal before starting the bot.

Classic mistake that gets everyone at least once. Wavelink throws that generic connection refused error without telling you the Lavalink server isn’t even running. When I started with music bots, I wasted hours debugging my Python code thinking it was a config problem. What’s really annoying is how Lavalink fails silently - your bot code looks perfect but nothing works because there’s no server on that port. Quick tip: check if Lavalink’s running by hitting http://localhost:2333 in your browser. If you get any response, the server’s up and your bot should connect.

Happens all the time, especially after trying to deploy stuff. Heroku deployments mess with your local env variables and you forget about background dependencies that were running. I’ve been burned by this twice - once with Lavalink, another with Redis. That connection error’s super misleading because it makes you think your code’s broken when the external service just isn’t running. Pro tip: make a batch file or shell script to auto-start Lavalink so you don’t have to remember that java command every time.

glad u sorted it out! had the same prob a while back and it drove me nuts. it’s super easy to overlook that lavalink needs to be running on its own. totally relatable, don’t stress it!

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.