discord token issues
sircisco
FREEOP

a month ago

Service: ElementalTest

Issue: Environment variable DISCORD_TOKEN is set in the Railway dashboard but not being injected into the container at runtime

Evidence: The variable shows as undefined in logs despite being configured

Steps taken: Renamed variable, redeployed multiple times, verified variable is set correctly in dashboard

This is a critical blocker for your bot, so they should prioritize it.

Solved$10 Bounty

Pinned Solution

a month ago

I see you have pending changes (at the top of the canvas). Can you confirm that you've actually deployed these? If you've created the variable but not deployed it, it won't actually exist on the service at deployment time.

8 Replies

Status changed to Open Railway 29 days ago


a month ago

Hello!

Can I just ask you to check a couple things:

  • Does the environment variable have a value set correctly?
  • If this is a an Environment-scoped (shared) variable, have you shared it with your bot's service?
  • Is your bot looking for DISCORD_TOKEN, or is it perhaps looking for an environment variable with a different name?
  • Is your bot definitely looking for an environment variable at all, or is it expecting it from something like a file?
  • Are you using a custom start command? If so, are you able to share what it is?

thaumanovic

Hello! Can I just ask you to check a couple things: - Does the environment variable have a value set correctly? - If this is a an Environment-scoped (shared) variable, have you shared it with your bot's service? - Is your bot looking for `DISCORD_TOKEN`, or is it perhaps looking for an environment variable with a different name? - Is your bot definitely looking for an environment variable at all, or is it expecting it from something like a file? - Are you using a custom start command? If so, are you able to share what it is?

sircisco
FREEOP

a month ago

Hi,

Thanks for the questions. I’ve checked everything on my side:

  • The environment variable is set correctly as DISCORD_TOKEN and has a valid value (no quotes or extra spaces).
  • It is added at the service level under the Production environment, not only project-level or preview.
  • My bot is correctly configured to use process.env.DISCORD_TOKEN.
  • The bot is not using any file-based token loading; it relies entirely on environment variables.
  • My start command is node index.js, and the service is using the correct entry file (index.js).
  • I’ve redeployed multiple times after updating variables, but the runtime still shows process.env.DISCORD_TOKEN as undefined, which suggests the variable is not being injected into the running service environment.

From my side, everything appears correctly configured, but the deployed service is still not receiving the environment variable at runtime.


a month ago

Can you update your start command to /bin/sh -c "node index.js" (or your main file) and see if that resolves?


thaumanovic

Can you update your start command to `/bin/sh -c "node index.js"` (or your main file) and see if that resolves?

sircisco
FREEOP

a month ago

still buggedd

Screenshot 2026-05-27 at 9.50.20 PM.png

Attachments


a month ago

If /bin/sh -c "node index.js" is still bugged, I’d stop testing the bot code for a minute and make Railway prove whether the env var exists before your app even starts.

Temporarily set the start command to:

/bin/sh -lc 'node -e "console.log(\"TOKEN_PRESENT=\" + Boolean(process.env.DISCORD_TOKEN)); console.log(\"NODE_ENV=\" + process.env.NODE_ENV); console.log(process.cwd())"; node index.js'

Don’t print the token itself, just that boolean.

If it prints TOKEN_PRESENT=false, then the screenshot/error is downstream of a Railway env/scope issue. In that case I’d check these exact things:

  • the variable change was reviewed/applied and a new deployment was created after it
  • DISCORD_TOKEN is on the ElementalTest service in the same Production environment that is actually running
  • there isn’t a second similar service/old deployment receiving traffic
  • if it’s a shared variable, it is explicitly shared with that service

If it prints TOKEN_PRESENT=true, then Railway is injecting it and the app is losing it after startup. Then I’d look for dotenv.config({ override: true }), a different entry file being started, or code reading a slightly different name like DISCORD_BOT_TOKEN.

The boolean line is the important split here. It tells you whether to chase Railway config or your Node startup path.


testuser123

If `/bin/sh -c "node index.js"` is still bugged, I’d stop testing the bot code for a minute and make Railway prove whether the env var exists before your app even starts. Temporarily set the start command to: ```bash /bin/sh -lc 'node -e "console.log(\"TOKEN_PRESENT=\" + Boolean(process.env.DISCORD_TOKEN)); console.log(\"NODE_ENV=\" + process.env.NODE_ENV); console.log(process.cwd())"; node index.js' ``` Don’t print the token itself, just that boolean. If it prints `TOKEN_PRESENT=false`, then the screenshot/error is downstream of a Railway env/scope issue. In that case I’d check these exact things: - the variable change was reviewed/applied and a new deployment was created after it - `DISCORD_TOKEN` is on the `ElementalTest` service in the same Production environment that is actually running - there isn’t a second similar service/old deployment receiving traffic - if it’s a shared variable, it is explicitly shared with that service If it prints `TOKEN_PRESENT=true`, then Railway is injecting it and the app is losing it after startup. Then I’d look for `dotenv.config({ override: true })`, a different entry file being started, or code reading a slightly different name like `DISCORD_BOT_TOKEN`. The boolean line is the important split here. It tells you whether to chase Railway config or your Node startup path.

sircisco
FREEOP

a month ago

still same error


a month ago

I see you have pending changes (at the top of the canvas). Can you confirm that you've actually deployed these? If you've created the variable but not deployed it, it won't actually exist on the service at deployment time.


thaumanovic

I see you have pending changes (at the top of the canvas). Can you confirm that you've actually deployed these? If you've created the variable but not deployed it, it won't actually exist on the service at deployment time.

sircisco
FREEOP

a month ago

seems this work now let me check


Status changed to Solved sam-a 28 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...