InvalidToken - TELEGRAM_TOKEN not found
kingsleysuoye556-arch
HOBBYOP

2 months ago

Service: superb-charisma / TapBumberReal4Bot

Description of the issue:

My Telegram bot crashes immediately on deploy.

Railway says the token is missing even though I added it.

Error message:

telegram.error.InvalidToken: You must provide the token!

$10 Bounty

50 Replies

Railway
BOT

2 months ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway • about 2 months ago


2 months ago

Make sure you have deployed the staged changes, when you save a variable, It will be saved as staged changes, you need to deploy the changes


Try logging the token into console and see what value you're getting.


kingsleysuoye556-arch
HOBBYOP

2 months ago

I redeployed after adding TELEGRAM_TOKEN.

I also added this to my code:

print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN"))

The logs show:

TOKEN VALUE: None

So the variable is set in Railway but os.getenv returns None in the container.

Attaching screenshot of my Variables tab.


kingsleysuoye556-arch

I redeployed after adding TELEGRAM_TOKEN. I also added this to my code: print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) The logs show: TOKEN VALUE: None So the variable is set in Railway but os.getenv returns None in the container. Attaching screenshot of my Variables tab.

manuproject
FREE

2 months ago

can you provide a screenshot maybe youre not doing it properly

cos its not detecting thats the issue


manuproject
FREE

2 months ago

also cherck they re no sapace or anyrhing after TELEGRAM_TOKEN


manuproject
FREE

2 months ago

also

whats your start command / how does the bot actually launch? if you have a dockerfile paste it, if not just paste your start command from railway settings. want to see if something in how the process launches is stripping the env var before it reaches your python code


kingsleysuoye556-arch
HOBBYOP

2 months ago

Attaching screenshot of my Variables tab.

I checked: The variable name is exactly TELEGRAM_TOKEN with no spaces before or after.

It's set on the service: TapBumberReal4Bot


Try removing the variable, redeploy, then add it back.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Did it. I removed TELEGRAM_TOKEN, redeployed, then added it back and redeployed again.

Checking logs now. Will update if TOKEN VALUE is still None.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-102724.jpg

Attachments


kingsleysuoye556-arch

![Screenshot_20260811-102724.jpg](https://station-server.railway.com/attachments/att_01kzr2wpdjfambkbkyx3k62m23)

manuproject
FREE

2 months ago

wht is this ??? this re tabs


kingsleysuoye556-arch
HOBBYOP

2 months ago

file_00000000736c81f6b3d56acfc4e86632.jpg

Attachments


kingsleysuoye556-arch

![file_00000000736c81f6b3d56acfc4e86632.jpg](https://station-server.railway.com/attachments/att_01kzr32v0rfapt497f1qhjvdhw)

manuproject
FREE

2 months ago

try and redeploy today after changing it this is on 6th today is 11th


It would help if you were able to paste the logs.

Also, is the token valid?

And make sure you’re checking the logs for the latest deployment, not the one from a few days ago.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-104512.jpg

Attachments


kingsleysuoye556-arch

![Screenshot_20260811-104512.jpg](https://station-server.railway.com/attachments/att_01kzr3e0nsesgtbt3kn1m0kbm7)

manuproject
FREE

2 months ago

the token is from BOTFATHER

go back to botfather in telegram, use /token or /mybots to get a fresh copy of the token, then go to railway variables, delete the current TELEGRAM_TOKEN value entirely and paste the fresh one in, save, redeploy. a valid token looks like 123456789:AAExampleFormatHere with a colon separating the numeric id from the hash, no quotes, no spaces


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-110251.jpg

Attachments


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-110434.jpg

Attachments


kingsleysuoye556-arch
HOBBYOP

2 months ago

Still crashing with InvalidToken.

I added print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) to my code.

Attaching screenshot of logs.

Can you check if there's an issue with environment variables on my project?

Service: TapBumberReal4Bot


manuproject
FREE

2 months ago

can u share a screenshot of your code re you using a pc or phone ??


kingsleysuoye556-arch

Still crashing with InvalidToken. I added print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) to my code. Attaching screenshot of logs. Can you check if there's an issue with environment variables on my project? Service: TapBumberReal4Bot

Does the code work in a local environment?


manuproject
FREE

2 months ago

but the two most recent crash logs showed a different error (BotFather format error, not None)


kingsleysuoye556-arch
HOBBYOP

2 months ago

I'm using my phone to deploy.

Attaching screenshot of the top of my code where I load the token.

I have:

import os

from telegram import Bot

print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN"))

TOKEN = os.getenv("TELEGRAM_TOKEN")

bot = Bot(token=TOKEN)


2 months ago

Enable desktop mode on your browser, open the deployment logs and click the download icon, then copy the logs content as text, then paste it here


kingsleysuoye556-arch
HOBBYOP

2 months ago

No, I haven't tested it locally. I'm only deploying on Railway with my phone.

I just generated a new token from BotFather and added it.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Yes that's why I revoked the old token.

The new error is: telegram.error.InvalidToken

Attaching screenshot of my code where I use os.getenv("TELEGRAM_TOKEN")


kingsleysuoye556-arch

Yes that's why I revoked the old token. The new error is: telegram.error.InvalidToken Attaching screenshot of my code where I use os.getenv("TELEGRAM_TOKEN")

manuproject
FREE

2 months ago

test locally and confirm its working before deploying on railway


kingsleysuoye556-arch
HOBBYOP

2 months ago

I can't test locally on phone.

But the error changed from None to InvalidToken after I added the new token,

so Railway is reading the variable now.

Waiting to paste the full logs as text once I enable desktop mode.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Hi, I'm ready to paste the full logs.

Just finished enabling desktop mode.

Is there anything specific you want me to look for in the logs before I paste?

Like should I check if the token has spaces or quotes?


kingsleysuoye556-arch

Hi, I'm ready to paste the full logs. Just finished enabling desktop mode. Is there anything specific you want me to look for in the logs before I paste? Like should I check if the token has spaces or quotes?

manuproject
FREE

2 months ago

verify the token is valid since u getting invaid token secondly check as u copy it and paste the token if they was no space added if the token is less than 32 i would suggest you type it one by one but since u said you have just a device so just copy and paste it and remove any space at the back of it


kingsleysuoye556-arch
HOBBYOP

2 months ago

Thank you!

I just copied a new token from @BotFather and pasted it in Railway Variables.

I removed any spaces at the back and front.

The token is 46 characters long and has : in the middle.

Deploying now. If it still fails I will paste the full logs here.


kingsleysuoye556-arch
HOBBYOP

2 months ago

Thank you!

I just copied a new token from @BotFather and pasted it in Railway Variables.

I removed any spaces at the back and front.

The token is 46 characters long and has : in the middle.

Deploying now. If it still fails I will paste the full logs here.


kingsleysuoye556-arch

Thank you! I just copied a new token from @BotFather and pasted it in Railway Variables. I removed any spaces at the back and front. The token is 46 characters long and has : in the middle. Deploying now. If it still fails I will paste the full logs here.

manuproject
FREE

2 months ago

okay if it works let us know if not lets know the new devepment


kingsleysuoye556-arch
HOBBYOP

2 months ago

@manupr... Update:

It deployed and showed "ACTIVE" for a bit, but then it CRASHED again.

New error is not InvalidToken anymore.

Screenshot of logs attached.

Can you please check the logs and tell me what caused the crash?

I think maybe another variable is missing.


Can you reupload the screenshot?


kingsleysuoye556-arch

@manupr... Update: It deployed and showed "ACTIVE" for a bit, but then it CRASHED again. New error is not InvalidToken anymore. Screenshot of logs attached. Can you please check the logs and tell me what caused the crash? I think maybe another variable is missing.

manuproject
FREE

2 months ago

okay then thats another thing need fixing

there was no picture in your last message we expecting the screenshot of the new error


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-135423.jpg

Attachments


Is that the latest deployment?


kingsleysuoye556-arch

![Screenshot_20260811-135423.jpg](https://station-server.railway.com/attachments/att_01kzre81fdfevtkdf960szmxpx)

manuproject
FREE

2 months ago

ur time here is 11:00 and current time o your phone is 1:54PM

thzts almost 3hours differ


kingsleysuoye556-arch
HOBBYOP

2 months ago

@manupr... Here is the screenshot of the CRASHED log.

It’s still showing:

telegram.error.InvalidToken: You must be tfather!

I updated the TELEGRAM_TOKEN in Variables and Redeployed,

but it looks like it’s still using the old token.

Do I need to delete the deployment and make a new one?

Or is there a cache I need to clear on Railway?

Thank you!


kingsleysuoye556-arch
HOBBYOP

2 months ago

@manupr... Yes I'm in Nigeria GMT+1 🙂

So 11:00 on Railway = 1:54PM my time. That makes sense.

But the main issue is still:

telegram.error.InvalidToken: You must be tfather!

I already updated TELEGRAM_TOKEN in Variables with the new token from BotFather

and clicked Redeploy, but it's still showing the old error.

Should I delete this deployment and create a new one?

Or is there a way to clear cache on Railway?


I would highly recommend testing the code locally first. We’re just going in circles at this point.


kingsleysuoye556-arch
HOBBYOP

2 months ago

@0x5b62656e5d Thanks for the advice 🙏

I don't have a computer to test locally right now.

I'm deploying straight to Railway from GitHub.

The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather,

but the logs still show: telegram.error.InvalidToken: You must be tfather!

Is it possible the bot is reading from a .env file in the repo instead of Railway Variables?

How do I force Railway to use the Variable instead?

Thank you!


Status changed to Solved 0x5b62656e5d • about 2 months ago


Status changed to Open 0x5b62656e5d • about 2 months ago


(Sorry misclicked)


kingsleysuoye556-arch

@0x5b62656e5d Thanks for the advice 🙏 I don't have a computer to test locally right now. I'm deploying straight to Railway from GitHub. The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather, but the logs still show: telegram.error.InvalidToken: You must be tfather! Is it possible the bot is reading from a .env file in the repo instead of Railway Variables? How do I force Railway to use the Variable instead? Thank you!

Again, to rule out a Railway issue, I don’t really have any other advice except to make sure that the code works in a local environment.


kingsleysuoye556-arch
HOBBYOP

2 months ago

@0x5b62656e5d Thanks for the advice 🙏

I don't have a computer to test locally right now.

I'm deploying straight to Railway from GitHub.

The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather,

but the logs still show: telegram.error.InvalidToken: You must be tfather!

Is it possible the bot is reading from a .env file in the repo instead of Railway Variables?

How do I force Railway to use the Variable instead?

Thank you!


kingsleysuoye556-arch
HOBBYOP

2 months ago

Thanks for the follow up @0x5b62656e5d 🙏

I tested it locally on my phone using Termux and the bot starts fine with the new token from my environment variable.

No .env file in repo. main.py is using: TOKEN = os.getenv("TELEGRAM_TOKEN")

The only error I get is on Railway: InvalidToken.

I already did Redeploy after updating the Variable.

Is there a way to completely clear the old build/cache on Railway so it forces a fresh deploy with the new token?

Thank you


kingsleysuoye556-arch

Thanks for the follow up @0x5b62656e5d 🙏 I tested it locally on my phone using Termux and the bot starts fine with the new token from my environment variable. No .env file in repo. main.py is using: TOKEN = os.getenv("TELEGRAM_TOKEN") The only error I get is on Railway: InvalidToken. I already did Redeploy after updating the Variable. Is there a way to completely clear the old build/cache on Railway so it forces a fresh deploy with the new token? Thank you

manuproject
FREE

2 months ago

delete the old build and redeploy remember use the same active token from TFATHER

no space at all


manuproject
FREE

2 months ago

if you can type it since its just 46 characters and u know you wont make mistake write it down and type it back inside stop the local and redeploy it


kingsleysuoye556-arch
HOBBYOP

2 months ago

Screenshot_20260811-145207.jpg

Attachments


Welcome!

Sign in to your Railway account to join the conversation.

Loading...