Deploying Java Discord bot JAR to Heroku - Port binding issues

I made a Discord bot using Java and packaged it as an executable JAR file. I’m trying to deploy it on Heroku since they offer free hosting hours each month. The bot works perfectly when I run it on my local machine, but when I deploy to Heroku I keep getting this error:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch

I think the issue is that my Discord bot doesn’t need to listen on Heroku’s web port since it connects directly to Discord’s servers via WebSocket. But Heroku expects web applications to bind to a specific port.

I tried updating my Procfile like this:

web: java $JAVA_OPTS -Dserver.port=$PORT -jar mybot.jar --host=0.0.0.0 --port=$PORT

But it still doesn’t work. The logs show my bot successfully connects to Discord’s gateway and receives messages, but then Heroku kills the process after 90 seconds because it’s not binding to the expected port.

How can I properly deploy a Discord bot on Heroku? Do I need to create a dummy web server that listens on the PORT variable? Or is there a different approach for hosting bots that don’t serve web content?

yeah, heroku dropped their free tier so check out alternatives like railway or render. if u still wanna use heroku, just change your Procfile from web: to worker: - this way it won’t attempt to bind to the port.

Had the exact same issue when I first deployed my Discord bot to Heroku. You’re using a web process type when Discord bots should run as worker processes. I spent hours trying to make dummy HTTP servers work before realizing the simple solution. What fixed it: switch to worker dynos and make sure your Java app doesn’t try to start any embedded web servers. Some frameworks like Spring Boot will automatically start Tomcat even if you don’t need it. If you’re using Spring Boot, add spring.main.web-application-type=none to your application.properties to prevent it from starting a web server. Also, you might need to adjust your dyno scaling through the Heroku dashboard after changing the Procfile, since it defaults to web dynos being enabled.

You’re getting that port error because Heroku’s web dynos expect apps to bind to a port within 90 seconds. Discord bots don’t serve HTTP traffic, so you need a worker dyno instead. Change your Procfile to worker: java $JAVA_OPTS -jar mybot.jar and ditch all the port arguments. Worker dynos handle background processes and don’t care about ports. After updating your Procfile, scale down web and scale up worker: heroku ps:scale web=0 worker=1. I’ve used this setup for all my Discord bots on Heroku - works perfectly without needing dummy web servers.