Node.js Discord bot doesn't seem to communicate

Hello everyone.

I’m new to this, and I have to admit I’m not a pro on node.js.

So long things short, I had a bot (a translator) working in heroku, and now I moved it to fly.io.
It is working, but duplicates it’s actions (sends 2 translations to each language), and I believe it still uses Heroku Postgrees DB, so I decided to upload a new instance (the DB only holds the channels config, so not to worry about losing it and do it again).

The problem is, altho it gets the bot online, it doesn’t respond to the commands i put in discord, so I assume it is not communicating.

I have the secrets set, but not sure it is the right way (I did as docs explain).
power_v1

Here’s my fly.toml code:

app = "translator-local"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  builder = "heroku/buildpacks:20"

[build.args]
  NODE_ENV = "production"

[env]
  DATABASE_URL = "process.env.DATABASE_URL"
  DISCORD_TOKEN = "process.env.DISCORD_TOKEN"
  NODE_MODULES_CACHE = "false"
  PORT = "8080"

What am I doing wrong?

Thank you in advance!

One thing I’ve noted is that you set the env values as these strings so DATABASE_URL is literally "process.env.DATABASE_URL" rather than your secret. I’d say remove those two from the [env] section and use only secrets for these. That might be able to help.

Otherwise…

I’m not used to discord bots at all but I assume it uses webhooks? Have you tried changing the webhook to hit your new URL from Fly? Looking into logs might be a nice place to start debugging

In case it uses longpolling that might explain why it replied twice as having two concurrent instances would make both of them get updates on a near time frame and both would reply thinking they are the only one doing it. But assuming it is using this method you might also want to look into logs to see if there’s nothing else happening.

2 Likes

First of all, thank you for your reply!

I removed those var from env as you suggested!

app = "translator-local"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  builder = "heroku/buildpacks:20"

[build.args]
  NODE_ENV = "production"

[env]
  NODE_MODULES_CACHE = false
  PORT = "8080"

Also, I removed the bot backup instances, migrated from Heroku, to ease the troubleshooting.

The bot uses it’s token (DISCORD_TOKEN) to communicate, and it does appear online (before deploying it was offline) but it still does not respond to any command!

I checked the logs, there are no errors in there and it returns 1 Shard online and 6 guilds.

I decided to upload the original bot (open source) and the behavior is exactly the same, gets online but that’s it.

It appears to be restarting: “Shutting down virtual machine”.

Since I don’t see any message saying it ran out of memory my next best guess is that your entry point (the command that runs on docker) is exiting after running can you verify that?

I do not have a Docker file, is there somewhere else to verify it?

I just run flyctl status command, ad it appears to be working

You can verify whats the command that runs your bot in production. It could be npm start and see if it exits.

Other than that, something might be failing silently

I guess it doesn’t exist…

Power0002

I will be troubleshooting as I go, as I do it as a hobby I might take a little longer :smiling_face_with_tear:

Is it possible to have something to do with outdated or deprecated dependencies?
As it runs on Heroku and works when imported from there, I wasn’t assuming it might be the issue.

Well I have some news.

I updated dependencies and been trying it out as I go in VSC (locally).
It is working on my computer, so I believe it means there are no errors stopping it from working, but it doesn’t work in Fly.io.
The simptoms are the same, it just doesn’t work, no errors or anything.
The only diference is the heroku:buildpack20 … Whitch was also used in Heroku … I’m lost at this point.

I used a Docker and let it build in debian:bullseye … here I got an error about missing gulp, but running locally, it works:

Am I missing some requirement in Fly?

Thank you in advance.

Hello, I’m back at it.

Eventually I found the issue.

The bot coundn’t connect to the FLY Postgres DB, and as I don’t have a time out set to the DB connection (because I don’t want the bot to stop running if it fails, as it can run with the cached data), it never gave any errors.

I have the bot hosted and working in Fly, connected to the Postgres Database in Heroku for about a week now.

Now I have to understand why the Fly DB doesn’t allow the bot to connect to it with both internal and external URLs (I had setup an external connection, and I can connect with TablePlus).

I could use some tips on FLY postgrees DB … anyway, I will come back once and if I solve it.