How to deploy a Discord.JS bot on Glitch? [ISSUE RESOLVED]

Please consider providing your Glitch project’s name in your post. Many problems are very difficult to troubleshoot without being able to see the code involved. Users who haven’t been invited to your project won’t be able to edit your code or see the secrets in your .env file just from your project name.

Alternatively provide some code that gives community members some context around your problem. Use the code formatting tool to make your code easier to read.

UPD: I will really appreciate if you guys could DM me your Discord IGns, so we could continue the discussion. Unfortunately my amount of replies here has hit its limit.

I’ve faced an issue regarding discord bot deployment on Glitch !

Following instructions I have created a Glitch account and manually uploaded all my files including index.js express.js watch.json package.json .gitignore and config.json .

Oddly enough the app status was OK, but the logs were showing cannot find module app/index.js . Therefore I tried running enable-npm which has only shown me more errors.

Eventually, I decided to run npm init once again and installing all modules for my project manually (discord.js, Sequelize, sqlite3, discord.js-commando, express). This did not help either.

To sum up, the issue is that I cannot get my bot up and running on Glitch. I will appreciate any help!

THE LINK TO MY PROJECT:https://glitch.com/~deadline-bot-app

Could you share you project/code?

Sure thing! I’ve added it!

I think you have it private.

Whoops! Still getting used to the platform. I thought the invite link would work. I’ made it public

Can you send a photo of your logs?

This is the error I get when I view your project:

  failed to start application on deadline-bot-arthub-app.glitch.me

  This is most likely because your project has a code error.
  Check your project logs, fix the error and try again.  

Got it.

Try replacing port with proccess.env.PORT.

Also, I saw this in your server.js file:
require("/app/express.js");

Replace it with:
require("/express.js");

The app folder doesn’t really exist as all the contents of your app are already in that folder.

Still getting the same exact error message :o

Try require(__dirname + '/express.js').

1 Like

Try this:
console.log("Your app is listening on port " + listener.address().port);

1 Like

If it works it should say 3000.

The full code:

app.listen(process.env.PORT || 3000, () => {
   console.log("Your app is listening on port " + listener.address().port);
});

Hope the arrow functions are correct.

1 Like

Example app listening on port 1988! :thinking:

Woah, 1988??? Is it on Glitch or your local machine?

Yeah, that should not be happening!

I sure did not mess up any setting there :smile:

1 Like

The app does seem to work.
https://deadline-bot-arthub-app.glitch.me/

Yeah, I got an “Ok”.