Heroku Discord Bot builds but doesn't work

倾然丶 夕夏残阳落幕 提交于 2021-01-29 20:22:23

问题


I am trying to host a discord bot on Heroku (Discord JDA, Maven). I do this by connecting to Github and then deploying. The bot 'deploys' (view attachment) but doesn't actually work (view attachment).

What could I be doing wrong, or has anyone else come across a similar issue?

screenshot


回答1:


Quick and dirty way to deploy it:

You'll need to setup a Procfile, extensive info on that right here: https://devcenter.heroku.com/articles/procfile

The procfile is basically a file with no extension that tells the dyno how to execute your program.

A simple

worker: java $JAVA_OPTS -jar <PATH_TO_JAR>

will work fine if you don't need more config, refer to that link for more.

You can then deploy it like this (Good to have procfile and jar on the same directory):

$ heroku deploy:jar -a <YOUR_HEROKU_APP_NAME> --jdk <JDK_VERSION> --jar <PATH_TO_JAR> -i Procfile

Then to start it just do (Assuming you want a worker dyno, which is what discord should need)

$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=1

Then stop it with:

$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=0

I've found this is much simpler than using git, especially if you're doing tests or simple/quick stuff.




回答2:


Possible solutions:

  1. Set up a Procfile. A Procfile basically tells Heroku what command to run when your app is deployed. Inside the Procfile, write worker: node index.js. Also, make sure Procfile has a capital "P".

  2. Set up package.json.

    npm init

Then just skip through the set up and your file should be automatically created. IMPORTANT. In your package.json file, add your node and npm versions.

node -v
npm -v

Then go an type this in your package.json.

"engines": {
     node: "your-version-here"
     npm: "your-version-here"
}
  1. Then try deploying your app to Heroku again. Also, make sure you have the "nodejs" buildpack set up for your app. Run it and test the discord bot.


来源:https://stackoverflow.com/questions/61692630/heroku-discord-bot-builds-but-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!