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
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
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)
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
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
Ah yea. So you also likely need a requirements file. You just put the libraries you use (mainly [discord.py](discord.py)
)
Traceback (most recent call last):
File "/app/main.py", line 134, in
[bot.run](bot.run)(os.environ["DISCORD_TOKEN"])
What is the full message? I am guessing you either didn't give the environ variable. Or you simply didn't import os
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.
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
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
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.
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.
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 …
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.
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.
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.
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
@BrodyUmmmm. There was a bit that went on. But honestly you could likely just do this one.