4 months ago
I've tried for a whole day.
156 Replies
4 months ago
Errors describe the token being invalid
4 months ago
Your Discord bot's token, likely
4 months ago
Hey, please attach the logs of your service.
4 months ago
The logs that your service produced before it has crashed (the text that is usually printed to the console). https://docs.railway.com/guides/logs
4 months ago
For example, you have shown the deploy logs here.
4 months ago
Go to your Discord bot's settings and enable the message content intent.

4 months ago
How is it now after you have restarted/redeployed the service?
Even if it show that my bot is online it stay offline and it crash after 10secs.
4 months ago
Please attach the logs.
4 months ago
Are you sure that the token you have provided is working (for example confirming it locally) and have you saved the changes (for the message content intent) in Discord's developer dashboard?
4 months ago
The bot's token can be reset and found under the Bot tab of your Discord bot. It is not under OAuth2.

4 months ago
You probably need to do it, if the bot token you provided is invalid. Resetting it will generate a new one that you should use on Railway.
Do I need to keep powershell open? (Python)
4 months ago
No, you don't need to keep powershell open.
4 months ago
Please share the logs again.
Slower?
4 months ago
Are you sure the token you have provided is valid? Does your code work locally?

4 months ago
And does the project correctly look at BOT_TOKEN env?
4 months ago
You are defining an environment/service variable named BOT_TOKEN, this value has to be looked up in your code. For example:
import os
BOT_TOKEN = os.getenv("BOT_TOKEN")
...4 months ago
It doesn't have to be exactly like that, you can name your variable whatever you want, depending on how you are using them in your code.
4 months ago
change
BOT_TOKEN="...."to
BOT_TOKEN = os.getenv("BOT_TOKEN")4 months ago
Don't hard code values in your code, especially after you have reset the token, meaning that the token you have hard coded is most likely invalid.
4 months ago
I suppose wherever you have defined BOT_TOKEN, in the snippet it would be at the start.
4 months ago
This is correct, if this is the only instance where you have defined BOT_TOKEN.
Good?
4 months ago
Commit and push the new changes so that Railway can roll out a new deployment with your changes.
4 months ago
Yes, you can use the terminal to commit and push your changes with git.
4 months ago
You still have to push it to GitHub.
4 months ago
Your repository's URL can be found on your GitHub profile, if you have already pushed it to GitHub.
4 months ago
Right next to Overview is Repositories (top left of your screenshot).
4 months ago
I suppose that you are trying to add your repository as the remote origin? HTTPS should work.
4 months ago
Just execute git push.
4 months ago
Use the first command if you are only using one branch.
4 months ago
git push origin HEAD:master
4 months ago
Check if Railway created a new deployment with your new changes.
4 months ago
Show the logs and does your code run locally?
Yes.
4 months ago
You need to include import os in your code, also you should use BOT_TOKEN = os.getenv("BOT_TOKEN")
4 months ago
In your code, import os at the very start and change the os.getenv call to actually read BOT_TOKEN, don't hard code it.
4 months ago
Add import os at the very start (line before import discord). Then change BOT_TOKEN = os.getenv("..........") to BOT_TOKEN = os.getenv("BOT_TOKEN")
4 months ago
No you don't.
4 months ago
Not good, the two imports should be in their own separate lines.
import os
import discord4 months ago
Also change the line where you define your BOT_TOKEN to
BOT_TOKEN = os.getenv("BOT_TOKEN")4 months ago
It is not, you are supposed to read from the environment variable called "BOT_TOKEN" and save it into a variable called BOT_TOKEN.
4 months ago
There is an error in your code, since you are reading the environment variable "MTQ2NT..." instead of "BOT_TOKEN" and save it in BOT_TOKEN.
4 months ago
This is wrong, you are not supposed to put the raw string/token in there.
4 months ago
Just "BOT_TOKEN"
4 months ago
Looks fine now, commit and push to GitHub now.
4 months ago
Pushing to GitHub will trigger a deployment on Railway.
4 months ago
Yes
Before I ran the command tell me if it's okay:
git add .
git commit -m "Initial Discord bot"
git push
4 months ago
Give it a more meaningful commit message such as "fix: os.getenv" and run them.
4 months ago
I strongly recommend you to learn the basics of Python/programming and git, without them it would be nearly impossible for you to do anything on your own. Especially with your current workflow being a complete black box, as you are not testing your code locally before pushing to production.
Run these commands for now:
git add .
git commit -m "fix: os.getenv"
git push origin HEAD:master4 months ago
Check Railway now.
4 months ago
You changed the token here to be the raw string (the actual token), right?
4 months ago
Yes
4 months ago
Yes
4 months ago
No
4 months ago
It will stay online 24/7 as long as it doesn't crash and your Railway subscription is still active.
4 months ago
Unhandled exceptions that could potentially occur.
4 months ago
I'll go ahead and mark this thread as solved. Please take my advice into consideration and learn the basics of Python (programming) and git, it will allow you to actually understand and catch these types of mistakes/errors in a matter of minutes as opposed to hours.
4 months ago
4 months ago
I am not sure if I am understanding your question right, but we have a place for general feedbacks regarding Railway at #🤗|feedback.
4 months ago
I am afraid that there is no feedback channel dedicated to "members" if you are referring to the Railway team.
Status changed to Solved uxuz • 4 months ago















