need help deploying

cadalt0
TRIAL

a year ago

Hello, I'm trying to deploy for the first time but I'm having trouble with it. I'm attempting to deploy on Railway because it's free, and right now I'm only looking for free deployment services. The file size is very small, so I won't need premium services. It consists of 134 lines of code, along with one .txt file and one .json file.

Script work perfectly fine on terminal no a single issue

Here is repo link :
https://github.com/cadalt0/discord-bot

Please let me know what I should do to deploy the bot. If you have other suggestions for free deployment methods, please share their details too. 🙏
Thank you!

0 Replies

cadalt0
TRIAL

a year ago

N/A


coderjoshdk
TRIAL

a year ago

Railway is not a free service. They have a free trail plan.

So what free options exist? None. You can self host. But that has its own issues.
There are no free options. There are cheap options (arguably this is one of them). But there are no free one. There do exist some cloud stuff that is free for like a year. But that is only for a year.


coderjoshdk
TRIAL

a year ago

ALSO. I didn't really read your code for more than 2 seconds. But a JSON file is a not so great DB. Railway doesn't have persistant file changes. They do have volumns. But that is slightly different


cadalt0
TRIAL

a year ago

I only need script running for 3 day max


coderjoshdk
TRIAL

a year ago

In that case. Railway is fine.


cadalt0
TRIAL

a year ago

Can you help me deploy? I have no idea how to deploy or add which files


coderjoshdk
TRIAL

a year ago

There is a discord template.
https://github.com/railwayapp-templates/discordpy-bot
You can try to copy what they do as a starting point. But it is outdated a bit.
But if the Procfile doesn't work. Basically, you will go into settings of the service and add a custom deploy start command. It would be python [main.py](main.py)

1261486091299459000


cadalt0
TRIAL

a year ago

Ok got it will try now , Thank you appreciate it


cadalt0
TRIAL

a year ago

Where should I add token?


coderjoshdk
TRIAL

a year ago

You should use [bot.run](bot.run)(os.environ["DISCORD_TOKEN"]) and the token will be an environment variable in the variables tab.
Just make sure to call it DISCORD_TOKEN

1261489755313406000


cadalt0
TRIAL

a year ago

okay got it


cadalt0
TRIAL

a year ago

failed


cadalt0
TRIAL

a year ago

2 warnings found (use --debug to expand):

  • UndefinedVar: Usage of undefined variable '$NIXPACKS_PATH' (line 18)

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 18)

Dockerfile:20

18 | ENV NIXPACKSPATH /opt/venv/bin:$NIXPACKSPATH

19 | COPY . /app/.

20 | >>> RUN --mount=type=cache,id=s/13fe26a2-54dc-454b-acb7-8c3bacb9d86f-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt

21 |

22 |

ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1

Error: Docker build failed

discord-bot | Railway


coderjoshdk
TRIAL

a year ago

Ah yea. So you also likely need a requirements file. You just put the libraries you use (mainly [discord.py](discord.py))


cadalt0
TRIAL

a year ago

I have it


cadalt0
TRIAL

a year ago

1261491316035162000


coderjoshdk
TRIAL

a year ago

json isn't a library. Well, it is. But it isn't a 3rd party one


cadalt0
TRIAL

a year ago

it was deployed then crashed


cadalt0
TRIAL

a year ago

Traceback (most recent call last):

File "/app/main.py", line 134, in

[bot.run](bot.run)(os.environ["DISCORD_TOKEN"])

coderjoshdk
TRIAL

a year ago

What is the full message? I am guessing you either didn't give the environ variable. Or you simply didn't import os


coderjoshdk
TRIAL

a year ago

Yea, do

import os

cadalt0
TRIAL

a year ago

Okay


cadalt0
TRIAL

a year ago

Yes


coderjoshdk
TRIAL

a year ago

Again though, you are likely going to run into an issue with your json file being forgotten. It won't save its update between deployments.


coderjoshdk
TRIAL

a year ago

If that isn't an issue <:shrug:747680403778699304> ignore me


cadalt0
TRIAL

a year ago

Then which data base you suggest?


cadalt0
TRIAL

a year ago

I only have to handle 300 mails address


coderjoshdk
TRIAL

a year ago

Hmmmmm. You only need this to be up for 3 days. You seem at least decently new to this side of stuff. So hard to actually recommend the right thing. But I guess a db is a good push. It will take some to learn and figure out. But in the long run if you want to learn code, that is a good thing to learn.
I would then recommend postgresql on railway. It is likely the easiest. You can actually look at the advanced example from dpy for how to handle a db.
But this is a lot of added complexity

The other solution is to just self host and leave your computer running for a few days. This actually might be the best option in this situation. Assuming you don't want to learn a bunch of little things with db stuff


coderjoshdk
TRIAL

a year ago

Actually actually. My real recommondation is to not use a bot. There shouldn't be any need for one with the way discord onboarding works. The only reason you would need it, is if you are trying to collect emails. And I mean, sure. But other than that, ehhh


cadalt0
TRIAL

a year ago

Yes I am new to these things
Data science is going to my work guessing I should start db asap
Probably from today, thanks for the push tho
Postgresql sounds good I would give it a try


cadalt0
TRIAL

a year ago

Leaving the computer running isn't possible for me


cadalt0
TRIAL

a year ago

I have only given access to the database to specific people mentioned. Doing this manually will be a lot of work, so I'm thinking a bot could handle it.


cadalt0
TRIAL

a year ago

You have a pretty fast typing


coderjoshdk
TRIAL

a year ago


coderjoshdk
TRIAL

a year ago

You can skip the logger stuff. And in your case, I don't think you need a ClientSession. But still good to note.


cadalt0
TRIAL

a year ago

Can I directly put token in repo ? And make it private?!


cadalt0
TRIAL

a year ago

This keep crashing


coderjoshdk
TRIAL

a year ago

I mean,,, you could. But that means you can never make the repo public. So I just wouldn't. The easier thing to do, is to have a local file called .env and put .env in .gitignore. And then use python-dotenv to import that file … but … yea, That is a lot of steps


coderjoshdk
TRIAL

a year ago

That can be a lot if you are new. It isn't complicated or hard. But it is becuase it is so many things at once …


coderjoshdk
TRIAL

a year ago

about 80 wpm. So actually pretty slow next to most people I know …


coderjoshdk
TRIAL

a year ago

https://github.com/theskumar/python-dotenv this is a good thing to learn / use.
And then for the more discord specific stuff, I actually would push you toward the dpy discord. https://discord.gg/dpy


coderjoshdk
TRIAL

a year ago

They have really amazing help forums. Well, I have not been there in a while. But I assume they are still great. They can help with everything. From DB stuff to discord stuff. To just simple python stuff.


cadalt0
TRIAL

a year ago

Will post another repo without token just for open source


cadalt0
TRIAL

a year ago

That insane 🚀


coderjoshdk
TRIAL

a year ago

You can do that. If you want to spend the time to learn "best practices", go take a look at the python-dotenv I sent.


coderjoshdk
TRIAL

a year ago

But yea, a lot all at once. So take your time


cadalt0
TRIAL

a year ago

Surely will check out once when bot starts


cadalt0
TRIAL

a year ago

I joined this server just few hrs back


cadalt0
TRIAL

a year ago

Thank you so much. I don't really have words to express my appreciation for your help. 🙏😭 My bot is running without any crashes or issues.


cadalt0
TRIAL

a year ago

You were absolutely right
It is not editing the Json data


cadalt0
TRIAL

a year ago

What should I use so it can add data in real time after command execution


coderjoshdk
TRIAL

a year ago

A DB


coderjoshdk
TRIAL

a year ago

And a volume. All still well within the trial stuff of railway


cadalt0
TRIAL

a year ago

I have to do this
If X user data is found in txt then allow and add their data to another sheet to make sure someone else don't user their data to join


cadalt0
TRIAL

a year ago

Will be possible do in free version?!


cadalt0
TRIAL

a year ago

ok thanks


coderjoshdk
TRIAL

a year ago

@BrodyUmmmm. There was a bit that went on. But honestly you could likely just do this one.


need help deploying - Railway Help Station