2 hours 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!
30 Replies
2 hours ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 2 hours ago
2 hours 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
2 hours ago
Try logging the token into console and see what value you're getting.
2 hours 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.
2 hours ago
can you provide a screenshot maybe youre not doing it properly
cos its not detecting thats the issue
2 hours ago
also cherck they re no sapace or anyrhing after TELEGRAM_TOKEN
2 hours 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
2 hours 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
2 hours 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

an hour ago
wht is this ??? this re tabs
kingsleysuoye556-arch

an hour ago
try and redeploy today after changing it this is on 6th today is 11th
an hour ago
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

an hour 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
an hour 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
an hour 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
an hour ago
Does the code work in a local environment?
an hour ago
but the two most recent crash logs showed a different error (BotFather format error, not None)
an hour 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)
an hour 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
an hour 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.
an hour 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")
an hour ago
test locally and confirm its working before deploying on railway
40 minutes 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.
15 minutes 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?
13 minutes 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