renesansz / discord-greeter-bot

My greeter bot for Discord
MIT License
49 stars 38 forks source link

Hosted on Heroku, no errors/issues, but my bot won't go online #270

Closed alxndriab closed 4 years ago

alxndriab commented 4 years ago

The problem is my bot won't stay online even though I followed the tutorial. After I deployed Heroku through my command prompt I got the same responses on the tutorial, and there was no warning or errors. I also put "scripts": { "start": "node server.js" }, in my package.json just to be sure but my bot is still offline and only remains online if I manually put npm start in my terminal. I looked at my build log in the Heroku website and it says -----> Build succeeded! ! This app may not specify any way to start a node process https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type. I don't know much about Git or Heroku nor when my bot should be online after I push it through Heroku.

OozoraHaruto commented 4 years ago

Hi, this should be in the packge.json file if you didn't rename any files, if you renamed your bot.js file then replace below with your file name appropriately.

"scripts": {
    "start": "node bot.js"
  },
alxndriab commented 4 years ago

Yes, following the tutorial I changed my main file to index.js and put

"scripts": {
    "start": "node index.js"
  }, 

in my package.json already, but the problem still persists.

OozoraHaruto commented 4 years ago

Hi, I have a few questions then. When you run your bot on your machine with node index.js does it work?

If yes, try going to your Heroku dashboard locate your application and go to settings, scroll down to buildpacks and add the nodejs buildback (this once gave me a problem with node.js) then edit your file abit and re push to heroku.

If this still don't work try and paste the error message here and your package.json file, I will try the best I can to help you

One last thing, ensure that at least 1 discord account that is linked to the bot is online or else you will get an error

2020-07-31T01:05:32.051720+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-07-31T01:05:32.077828+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-31T01:05:32.217048+00:00 heroku[web.1]: Process exited with status 137
2020-07-31T01:05:32.332357+00:00 heroku[web.1]: State changed from starting to crashed
alxndriab commented 4 years ago

Yes, I can run my bot locally with node index.js and I believe heroku already had the buildpack because I can see heroku/nodejs in buildpacks. This was the error message I could find in the build log in Heroku when I tried to deploy. Let me know if you mean something else

!   This app may not specify any way to start a node process
          https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type

Here's a link to my package.json file

Thank you for the help! Though if I need to try to re-push/re-deploy Heroku, I would need help with that.

OozoraHaruto commented 4 years ago

ok I tried your whole project and the problem is your package.json file. On the first line there shouldn't be any comments, that caused the error, executing npm install would tell you that there is an error in your file

next is the way you store your API file. Please follow the tutorial and switch to use dotenv it is a more secure way to store your api key keeping it in a json file is not advised. with the env file you can just connect your GitHub to Heroku to setup auto deployment every time you push to GitHub.

alxndriab commented 4 years ago

Ok, essentially I had to start from scratch, including downloading dotenv and creating a new file. Here is the updated github for it. Some changes I did was and the main problem is:

  1. In my package.json I changed the "main": "index.js", to "main": "bot.js", because the tutorial used bot.js
  2. I don't know why but my command terminal did not recognize touch as a command, so I had to manually create a .env file. I assumed it was called config.env. That might be a problem, so I will need help creating a .env file manually.
  3. The main problem was that now node bot.js does not work. In which it brought back a string of errors including [TOKEN INVAILD]
OozoraHaruto commented 4 years ago

You actually didn't have to redo it, but it's okay

  1. You need to add "start": "node bot.js" to ensure npm start works
  2. touch is a linux command so if you use windows I don't think it will work, just rename your config.env to .env changing this will get the compiler to read the token (doing this will also ensure your .env will not be pushed to GitHub) thus, it is more secure :)
alxndriab commented 4 years ago

Thanks! I deleted my old app and re-created it and pushed my new one. It looks like everything good and set up! Last question, say I wanted to make some changes, better my bot, and add some APIs, how would I push that to update my git that's attach to Heroku?

OozoraHaruto commented 4 years ago

No problem :)

  1. If you've your GitHub connected to Heroku in your app (on Heroku), under deploy there you can set the automatic deployment or manual deployment to the git project.
  2. If you do not want to connect your GitHub to Heroku or just think command line is cool, Here are some documentation from Heroku:

Edit 1: do close the issue if the problem is solved :D Edit 2: Hi do not forget to download the .gitignore of this project and add to your project, your .env file shouldn't be pushed to GitHub, if you cannot get rid of it from GitHub, move it to another folder push the project and move the .env file back, remember the .gitignore file has to be pushed together when you move the .env file out of the folder Edit 3: use git status to ensure that files with API keys are not pushed and are only on your machine :D

alxndriab commented 4 years ago

Alright, thank you for all the resources and help!