21 days ago
greetings everybody , sooo i tried deploying my discord bot for the first time through railway , with all the variables set , but the bot keeps crashing
idk what to do , please help .
Attachments
Pinned Solution
21 days ago
confirmed, its exactly the token. DiscordjsError [TokenInvalid]: An invalid token was provided from Client.login. railway is just auto-restarting it in a loop, which is why you see it crash every couple seconds, that wont fix itself.
go to your service → Variables tab on railway (not the .env file in your repo) and check DISCORD_TOKEN there. its either missing, empty, or still the placeholder from .env.example. get your real token from the discord developer portal → your application → bot → reset token (grab it fresh, you cant view an old one again), paste that into the railway variable, save, it'll auto redeploy.
also since a token sample was committed to .env.example, if that ever contained a real token at any point discord already auto-revoked it the moment it hit a public repo, so youd need a fresh one from the portal either way
9 Replies
21 days ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • 21 days ago
21 days ago
quick thing to check first: railway doesnt read .env or .env.example files at all, those only matter locally. your bot's actual token has to be set in the service's Variables tab directly (not in a committed file). given your last commit touched .env.example with a "sample token", double check the real DISCORD_TOKEN variable on railway isnt still the placeholder value or empty, thats the single most common reason a discord bot crashes instantly on its first deploy.
also, never put a real bot token in .env.example even as a sample and commit it, if that ever was a real token discord will auto-revoke it once its pushed to a public repo.
can you paste the crash logs (view logs on the crashed deployment)? that'll show the exact error but 9 times out of 10 for a first deploy its an invalid/missing token or missing gateway intents enabled in the discord developer portal
manuproject
quick thing to check first: railway doesnt read .env or .env.example files at all, those only matter locally. your bot's actual token has to be set in the service's Variables tab directly (not in a committed file). given your last commit touched .env.example with a "sample token", double check the real DISCORD_TOKEN variable on railway isnt still the placeholder value or empty, thats the single most common reason a discord bot crashes instantly on its first deploy. also, never put a real bot token in .env.example even as a sample and commit it, if that ever was a real token discord will auto-revoke it once its pushed to a public repo. can you paste the crash logs (view logs on the crashed deployment)? that'll show the exact error but 9 times out of 10 for a first deploy its an invalid/missing token or missing gateway intents enabled in the discord developer portal
21 days ago
here they are for you and mayori
Attachments
mayori
Can you share the error message on your Deploy Logs?
21 days ago
here they are
Attachments
21 days ago
Make sure you have define all the required environment variables on the Variables Tab
mayori
Make sure you have define all the required environment variables on the Variables Tab
21 days ago
even tho they are already set but through the env
Attachments
21 days ago
I just checked your repo, you just exposed your Bot Token in the source code (on the env example file specifically), and usually Discord will automatically reset Bot Token that exposed on GitHub, if the token you put in the Variables is the same as you put in the example file, that's why it didn't work, that explained why the error say the bot token is invalid, not missing
You can try generate a new Bot Token on your Developer Portal and paste it in the Variables Tab
aichakhadi73-lab
even tho they are already set but through the env 
21 days ago
confirmed, its exactly the token. DiscordjsError [TokenInvalid]: An invalid token was provided from Client.login. railway is just auto-restarting it in a loop, which is why you see it crash every couple seconds, that wont fix itself.
go to your service → Variables tab on railway (not the .env file in your repo) and check DISCORD_TOKEN there. its either missing, empty, or still the placeholder from .env.example. get your real token from the discord developer portal → your application → bot → reset token (grab it fresh, you cant view an old one again), paste that into the railway variable, save, it'll auto redeploy.
also since a token sample was committed to .env.example, if that ever contained a real token at any point discord already auto-revoked it the moment it hit a public repo, so youd need a fresh one from the portal either way
mayori
I just checked your repo, you just exposed your Bot Token in the source code (on the env example file specifically), and usually Discord will automatically reset Bot Token that exposed on GitHub, if the token you put in the Variables is the same as you put in the example file, that's why it didn't work, that explained why the error say the bot token is invalid, not missing You can try generate a new Bot Token on your Developer Portal and paste it in the Variables Tab
21 days ago
understood mate , appreciate your help you ad manuproject , thank you mates
Status changed to Solved medim • 17 days ago