R
Railway4mo ago
Cadalt

need help deploying

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!
GitHub
GitHub - cadalt0/discord-bot
Contribute to cadalt0/discord-bot development by creating an account on GitHub.
Solution:
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...
No description
Jump to solution
30 Replies
Percy
Percy4mo ago
Project ID: N/A
Cadalt
Cadalt4mo ago
N/A
Joshie
Joshie4mo 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. 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
Cadalt
Cadalt4mo ago
I only need script running for 3 day max
Joshie
Joshie4mo ago
In that case. Railway is fine.
Cadalt
Cadalt4mo ago
Can you help me deploy? I have no idea how to deploy or add which files
Solution
Joshie
Joshie4mo 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
No description
Cadalt
Cadalt4mo ago
Ok got it will try now , Thank you appreciate it Where should I add token?
Joshie
Joshie4mo ago
You should use 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
No description
Cadalt
Cadalt4mo ago
okay got it failed 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 NIXPACKS_PATH /opt/venv/bin:$NIXPACKS_PATH 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
Joshie
Joshie4mo ago
Ah yea. So you also likely need a requirements file. You just put the libraries you use (mainly discord.py)
Cadalt
Cadalt4mo ago
I have it
Cadalt
Cadalt4mo ago
No description
Joshie
Joshie4mo ago
json isn't a library. Well, it is. But it isn't a 3rd party one
Cadalt
Cadalt4mo ago
it was deployed then crashed Traceback (most recent call last): File "/app/main.py", line 134, in <module> bot.run(os.environ["DISCORD_TOKEN"])
Joshie
Joshie4mo ago
What is the full message? I am guessing you either didn't give the environ variable. Or you simply didn't import os Yea, do
import os
import os
Cadalt
Cadalt4mo ago
Okay Yes
Joshie
Joshie4mo 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. If that isn't an issue :shrug: ignore me
Cadalt
Cadalt4mo ago
Then which data base you suggest? I only have to handle 300 mails address
Joshie
Joshie4mo 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 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
Cadalt
Cadalt4mo 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 Leaving the computer running isn't possible for me 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. You have a pretty fast typing
Joshie
Joshie4mo ago
Here is that advanced setup I was talking about https://github.com/Rapptz/discord.py/blob/master/examples/advanced_startup.py You can skip the logger stuff. And in your case, I don't think you need a ClientSession. But still good to note.
Cadalt
Cadalt4mo ago
Can I directly put token in repo ? And make it private?! This keep crashing
Joshie
Joshie4mo 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 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 ... about 80 wpm. So actually pretty slow next to most people I know ... 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 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.
Cadalt
Cadalt4mo ago
Will post another repo without token just for open source That insane 🚀
Joshie
Joshie4mo 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. But yea, a lot all at once. So take your time
Cadalt
Cadalt4mo ago
Surely will check out once when bot starts I joined this server just few hrs back 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. You were absolutely right It is not editing the Json data What should I use so it can add data in real time after command execution
Joshie
Joshie4mo ago
A DB And a volume. All still well within the trial stuff of railway
Cadalt
Cadalt4mo ago
ok thanks
Joshie
Joshie4mo ago
@BrodyUmmmm. There was a bit that went on. But honestly you could likely just do this one.
Want results from more Discord servers?
Add your server