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:Glitch: The friendly community where everyone builds the web

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”.

Wait, I have reason to suspect that your Debugger is still active…

It may be showing it, but the bot itself doesn’t seem to be working…

Can you check if the Debugger is still running? If it is, can you stop the Debugger?

1 Like

Also, did you add the bot’s token into the .env file?

Yeah, I got it stopped

1 Like

Yes, I did, that’s true

Hmm… I guess we can check if you bot if banned from discord. Do you have anymore error in the logs?

I think I know why…

1 Like

Nope, no way my bot is banned :slight_smile:

Its possible. Glitch containers can get banned.

I think I found it! @JoshJson, can you paste the following code at the bottom of index.js?

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

In index.js, not express.js! And I made a small edit to the above code.

This line might also have something to do with it.
bot.login(token)

1 Like

No, I know what the error is. I made a small edit to the code I posted above, using it should fix it.

Now the error is about defining Express.

Now it should work.  

1 Like

Hey, if you are still up to helping, can you DM me your discord at @JoshJson , I didn’t realise there were limits on replies

Hey what’s up. Can you hit me up on discord, DM me at @JoshJson . Didn’t know that reply limit was a thing lol

1 Like

@JoshJson join this Discord server so that we’ll be able to help you:

2 Likes