Skip to content
deployment won't load variables
bencrawford26
OP

a year ago

I've deployed a discord bot and set my bot token under variables as DISCORD_TOKEN so I can access it like so in my code:

client.login(process.env.DISCORD_TOKEN);

but it keeps throwing the following error

/app/node_modules/discord.js/src/client/Client.js:217

if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);

^

Error [TokenInvalid]: An invalid token was provided.

at Client.login (/app/node_modules/discord.js/src/client/Client.js:217:52)

at Object. (/app/index.js:193:8)

at Module._compile (node:internal/modules/cjs/loader:1706:14)

at Object..js (node:internal/modules/cjs/loader:1839:10)

at Module.load (node:internal/modules/cjs/loader:1441:32)

at Function._load (node:internal/modules/cjs/loader:1263:12)

at TracingChannel.traceSync (node:diagnostics_channel:328:14)

at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)

at node:internal/main/run_main_module:36:49 {

code: 'TokenInvalid'

}

Node.js v22.21.1

Solved$15 Bounty

Pinned Solution

domehane

a year ago

i think he should after adding the variable in railway's variables tab, he need to click the "deploy" button at the top to apply the staged changes. railway doesn't automatically redeploy when you add variables; you have to manually deploy those changes for them to take effect that's why your token is showing as undefined

9 Replies

a year ago

Hey, have you tried to use the same token locally to see if it is actually valid? Furthermore, can you share your service's variable tab to confirm that it is actually defined there?


uxuz

Hey, have you tried to use the same token locally to see if it is actually valid? Furthermore, can you share your service's variable tab to confirm that it is actually defined there?

domehane

a year ago

i think he should after adding the variable in railway's variables tab, he need to click the "deploy" button at the top to apply the staged changes. railway doesn't automatically redeploy when you add variables; you have to manually deploy those changes for them to take effect that's why your token is showing as undefined


domehane

a year ago

also verify the token is actually valid (test it locally first) and there's no typo in the variable name (DISCORD_TOKEN matches exactly)


You can also ssh into the container and echo the variable name to make sure it exists.


no7r34l

a year ago

Make sure the token in Railway has no extra spaces or line breaks (copy it into a text editor first and double-check), and that it’s a current bot token from the Discord Developer Portal, not an old or user token.


bencrawford26
OP

a year ago

I've just tested locally with the same token and it works as normal. Tried doing a redeploy as well and it still crashed with the same error. I have attached a screenshot of my variables tab. Reset the discord token just to be sure and tried locally and redeploying. Worked locally but not through railway. No idea what I'm missing.


bencrawford26
OP

a year ago

Realised the issue. Apparently the changes still weren't applied after the deploy. Had to click the deploy button in the centre of the screen as opposed to the one on the previous deplyment.


domehane

i think he should after adding the variable in railway's variables tab, he need to click the "deploy" button at the top to apply the staged changes. railway doesn't automatically redeploy when you add variables; you have to manually deploy those changes for them to take effect that's why your token is showing as undefined

domehane

a year ago

this is exactly what i tell you in my first comment


bencrawford26

Realised the issue. Apparently the changes still weren't applied after the deploy. Had to click the deploy button in the centre of the screen as opposed to the one on the previous deplyment.

domehane

a year ago

.


Status changed to Open ray-chen • 11 months ago


Status changed to Solved ray-chen • 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...