I need assistance to keep my bot online. It always crash.
nathannganya-cyber
FREEOP

13 days ago

I've tried for a whole day.

Solved

156 Replies

Errors describe the token being invalid


nathannganya-cyber
FREEOP

12 days ago

The token is invalid?


Your Discord bot's token, likely


nathannganya-cyber
FREEOP

12 days ago

Okay I will change it and give you news.


nathannganya-cyber
FREEOP

12 days ago

It worked but crashed after.


nathannganya-cyber
FREEOP

12 days ago


uxuz
MODERATOR

12 days ago

Hey, please attach the logs of your service.


nathannganya-cyber
FREEOP

12 days ago

What do you mean?


uxuz
MODERATOR

12 days 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


uxuz
MODERATOR

12 days ago

For example, you have shown the deploy logs here.


nathannganya-cyber
FREEOP

12 days ago


nathannganya-cyber
FREEOP

12 days ago

Good?


uxuz
MODERATOR

12 days ago

Go to your Discord bot's settings and enable the message content intent.

1467585273973182700


nathannganya-cyber
FREEOP

12 days ago

Done. Reply to me or I won't get a notification.


uxuz
MODERATOR

12 days ago

How is it now after you have restarted/redeployed the service?


nathannganya-cyber
FREEOP

12 days ago

Even if it show that my bot is online it stay offline and it crash after 10secs.

1467588839945142292


uxuz
MODERATOR

12 days ago

Please attach the logs.


nathannganya-cyber
FREEOP

12 days ago


nathannganya-cyber
FREEOP

12 days ago

Here


uxuz
MODERATOR

12 days 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?


nathannganya-cyber
FREEOP

12 days ago

Here


nathannganya-cyber
FREEOP

12 days ago


nathannganya-cyber
FREEOP

12 days ago

Does the video work?


uxuz
MODERATOR

12 days ago

The bot's token can be reset and found under the Bot tab of your Discord bot. It is not under OAuth2.

1467593754209816800


nathannganya-cyber
FREEOP

12 days ago

You want me to reset the token?


uxuz
MODERATOR

12 days 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.


nathannganya-cyber
FREEOP

12 days ago

Okay.


nathannganya-cyber
FREEOP

12 days ago

Do I need to keep powershell open? (Python)

1467595601905586206


uxuz
MODERATOR

12 days ago

No, you don't need to keep powershell open.


nathannganya-cyber
FREEOP

12 days ago

Okay. So what's the problem now?


uxuz
MODERATOR

12 days ago

Please share the logs again.


nathannganya-cyber
FREEOP

12 days ago


uxuz
MODERATOR

12 days ago

Are you sure the token you have provided is valid? Does your code work locally?

1467597664853164000


nathannganya-cyber
FREEOP

12 days ago

I would like to show you the token but I can't


nathannganya-cyber
FREEOP

12 days ago

I paste the token here right?

1467598112779407400


nathannganya-cyber
FREEOP

12 days ago

I've hide the token.


nathannganya-cyber
FREEOP

12 days ago

@astrid(irl)*


And does the project correctly look at BOT_TOKEN env?


nathannganya-cyber
FREEOP

12 days ago

Wdym?


uxuz
MODERATOR

12 days 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")
...

nathannganya-cyber
FREEOP

12 days ago

Exacltly like that?


uxuz
MODERATOR

12 days 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.


nathannganya-cyber
FREEOP

12 days ago

Wait I'm gonna show u something. It maybe gonna help you.


nathannganya-cyber
FREEOP

12 days ago

Do you need this?

1467601252647964700


uxuz
MODERATOR

12 days ago

change

BOT_TOKEN="...."

to

BOT_TOKEN = os.getenv("BOT_TOKEN")

uxuz
MODERATOR

12 days 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.


nathannganya-cyber
FREEOP

12 days ago

Everywhere or only at the start?


uxuz
MODERATOR

12 days ago

I suppose wherever you have defined BOT_TOKEN, in the snippet it would be at the start.


nathannganya-cyber
FREEOP

12 days ago

If I understand only at the start right?


uxuz
MODERATOR

12 days ago

This is correct, if this is the only instance where you have defined BOT_TOKEN.


nathannganya-cyber
FREEOP

12 days ago


nathannganya-cyber
FREEOP

12 days ago

What next


nathannganya-cyber
FREEOP

12 days ago

The token is up


nathannganya-cyber
FREEOP

12 days ago

I just didn't show it


uxuz
MODERATOR

12 days ago

Commit and push the new changes so that Railway can roll out a new deployment with your changes.


nathannganya-cyber
FREEOP

12 days ago

I push it with powershell right?


uxuz
MODERATOR

12 days ago

Yes, you can use the terminal to commit and push your changes with git.


nathannganya-cyber
FREEOP

12 days ago

Good?

1467606732170854400


uxuz
MODERATOR

12 days ago

You still have to push it to GitHub.


nathannganya-cyber
FREEOP

12 days ago

Do you know where do I find my repo URL?


uxuz
MODERATOR

12 days ago

Your repository's URL can be found on your GitHub profile, if you have already pushed it to GitHub.


nathannganya-cyber
FREEOP

12 days ago

Huh where?

1467608569313759200


uxuz
MODERATOR

12 days ago

Right next to Overview is Repositories (top left of your screenshot).


nathannganya-cyber
FREEOP

12 days ago

Found it.


nathannganya-cyber
FREEOP

12 days ago

I've found it thank you.


nathannganya-cyber
FREEOP

12 days ago

1467609128993296600


nathannganya-cyber
FREEOP

12 days ago

HTTPS right?


uxuz
MODERATOR

12 days ago

I suppose that you are trying to add your repository as the remote origin? HTTPS should work.


nathannganya-cyber
FREEOP

12 days ago

Yes. Did it work?

1467609945821151500


uxuz
MODERATOR

12 days ago

Just execute git push.


nathannganya-cyber
FREEOP

12 days ago

Done.

1467610356666073300


nathannganya-cyber
FREEOP

12 days ago

Next?


uxuz
MODERATOR

12 days ago

Use the first command if you are only using one branch.


nathannganya-cyber
FREEOP

12 days ago

My bad but what command are you talking about?


uxuz
MODERATOR

12 days ago

git push origin HEAD:master


nathannganya-cyber
FREEOP

12 days ago

Done. After that?

1467611537870029000


nathannganya-cyber
FREEOP

12 days ago

.


uxuz
MODERATOR

12 days ago

Check if Railway created a new deployment with your new changes.


nathannganya-cyber
FREEOP

12 days ago

I think I'm cooked..

1467612218949501000


nathannganya-cyber
FREEOP

12 days ago

But it deployed 3mins ago


uxuz
MODERATOR

12 days ago

Show the logs and does your code run locally?


nathannganya-cyber
FREEOP

12 days ago


nathannganya-cyber
FREEOP

12 days ago

With powershell.


nathannganya-cyber
FREEOP

12 days ago

I juste write 2 commands and the bot go online


uxuz
MODERATOR

12 days ago

You need to include import os in your code, also you should use BOT_TOKEN = os.getenv("BOT_TOKEN")


nathannganya-cyber
FREEOP

12 days ago

How? You will really need to guide me for that.


nathannganya-cyber
FREEOP

12 days ago

where?


uxuz
MODERATOR

12 days 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.



nathannganya-cyber
FREEOP

12 days ago

Here?

1467614143925457000


nathannganya-cyber
FREEOP

12 days ago

I change it here?


uxuz
MODERATOR

12 days 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")


nathannganya-cyber
FREEOP

12 days ago

Do I erase import discord?


uxuz
MODERATOR

12 days ago

No you don't.


nathannganya-cyber
FREEOP

12 days ago

Good?

1467615432629424400


uxuz
MODERATOR

12 days ago

Not good, the two imports should be in their own separate lines.

import os
import discord

nathannganya-cyber
FREEOP

12 days ago

Alright.


nathannganya-cyber
FREEOP

12 days ago

Should be good now.

1467616335348371700


uxuz
MODERATOR

12 days ago

Also change the line where you define your BOT_TOKEN to

BOT_TOKEN = os.getenv("BOT_TOKEN")

nathannganya-cyber
FREEOP

12 days ago

What the difference?


nathannganya-cyber
FREEOP

12 days ago

It's the same.


uxuz
MODERATOR

12 days ago

It is not, you are supposed to read from the environment variable called "BOTTOKEN" and save it into a variable called BOTTOKEN.


uxuz
MODERATOR

12 days 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.


nathannganya-cyber
FREEOP

12 days ago

Wait I don,t understand. I don't put my token in ("BOT_TOKEN")?


nathannganya-cyber
FREEOP

12 days ago

This is what I've done.


nathannganya-cyber
FREEOP

12 days ago

1467617195021439000


uxuz
MODERATOR

12 days ago

This is wrong, you are not supposed to put the raw string/token in there.


uxuz
MODERATOR

12 days ago

Just "BOT_TOKEN"


nathannganya-cyber
FREEOP

12 days ago

Okay.


nathannganya-cyber
FREEOP

12 days ago

Good?

1467617539805675800


nathannganya-cyber
FREEOP

12 days ago

My bad if it's long.


uxuz
MODERATOR

12 days ago

Looks fine now, commit and push to GitHub now.


nathannganya-cyber
FREEOP

12 days ago

to gitbuh or railway?


uxuz
MODERATOR

12 days ago

Pushing to GitHub will trigger a deployment on Railway.


nathannganya-cyber
FREEOP

12 days ago

This commands? git add .
git commit -m "name"
git push


uxuz
MODERATOR

12 days ago

Yes


nathannganya-cyber
FREEOP

12 days ago

Do I use this too? git push origin HEAD:master


nathannganya-cyber
FREEOP

12 days ago

Before I ran the command tell me if it's okay:
git add .
git commit -m "Initial Discord bot"
git push


uxuz
MODERATOR

12 days ago

Give it a more meaningful commit message such as "fix: os.getenv" and run them.


nathannganya-cyber
FREEOP

12 days ago

I understand nothing 😭


uxuz
MODERATOR

12 days 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:master

nathannganya-cyber
FREEOP

12 days ago

I will. Good?

1467622737915678700


uxuz
MODERATOR

12 days ago

Check Railway now.


nathannganya-cyber
FREEOP

12 days ago

Deploy? (I've changed the token that why there's a change)


nathannganya-cyber
FREEOP

12 days ago

1467623455447847000


uxuz
MODERATOR

12 days ago

You changed the token here to be the raw string (the actual token), right?


nathannganya-cyber
FREEOP

12 days ago

I just reset the token and paste it here?


uxuz
MODERATOR

12 days ago

Yes


nathannganya-cyber
FREEOP

12 days ago

Yeah that what I've done.


nathannganya-cyber
FREEOP

12 days ago

I can deploy now?


uxuz
MODERATOR

12 days ago

Yes


nathannganya-cyber
FREEOP

12 days ago

I will record and last thing


nathannganya-cyber
FREEOP

12 days ago

Do I need to make it go online on powershell first?


uxuz
MODERATOR

12 days ago

No


nathannganya-cyber
FREEOP

12 days ago

Okay


nathannganya-cyber
FREEOP

12 days ago

IT WORKED


nathannganya-cyber
FREEOP

12 days ago

.


nathannganya-cyber
FREEOP

12 days ago

Now it gonna stay 24/7 right?


nathannganya-cyber
FREEOP

12 days ago

Or I need another site?


uxuz
MODERATOR

12 days ago

It will stay online 24/7 as long as it doesn't crash and your Railway subscription is still active.


nathannganya-cyber
FREEOP

12 days ago

How can it crash?


nathannganya-cyber
FREEOP

12 days ago

For what reason?


uxuz
MODERATOR

12 days ago

Unhandled exceptions that could potentially occur.


nathannganya-cyber
FREEOP

12 days ago

Alright. Thank you :3


nathannganya-cyber
FREEOP

12 days ago


uxuz
MODERATOR

12 days 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.


nathannganya-cyber
FREEOP

12 days ago

Do you have a link for that?



nathannganya-cyber
FREEOP

12 days ago

Can you close this ticket in 10mins?


nathannganya-cyber
FREEOP

12 days ago

Not now.


nathannganya-cyber
FREEOP

12 days ago

Where is the staff feedback channel?


uxuz
MODERATOR

12 days ago

I am not sure if I am understanding your question right, but we have a place for general feedbacks regarding Railway at #🤗|feedback.


nathannganya-cyber
FREEOP

12 days ago

And for members?


uxuz
MODERATOR

12 days ago

I am afraid that there is no feedback channel dedicated to "members" if you are referring to the Railway team.


nathannganya-cyber
FREEOP

12 days ago

Aww. You deserved five starts.


nathannganya-cyber
FREEOP

12 days ago

You can close this. Thank you for your incredible help, :3


Status changed to Solved uxuz 12 days ago


Loading...