R
Railway•3mo ago
Reth

Discord Bot not working - Command not found

Hi there, I am new to discord coding, as well as python and all the modern stuff regarding deploying of such kind of things. So I also do not yet have a real clue how these things are working out in railway. I just created an account and moved my python dicsord bot from replit to github. Then I connected my repo and deployed it. For this I used the discord python bot template. The bot is running and connects to discord - but it is not working at all unfortunately. The command is not found and hence the autocompletion not working. Any idea what I can do about this? I can also post source, error messages etc. - just let me know what is needed. (A quick search for the term "bot" at the search here top right resulted in 0 entries for me unfortunately). Project ID: 8c1db389-9532-4ead-9ee9-2f4b19a5334c Thank you in advance!
42 Replies
Percy
Percy•3mo ago
Project ID: 8c1db389-9532-4ead-9ee9-2f4b19a5334c
Reth
Reth•3mo ago
Project ID: 8c1db389-9532-4ead-9ee9-2f4b19a5334c
Brody
Brody•3mo ago
if you deployed the template then you arent running your code, you would be running the template's code
Reth
Reth•3mo ago
Hmm, but I had to connect my repo for it. How can I get this solved to let it run my code?
Brody
Brody•3mo ago
show me a screenshot of the source in your service settings please
Reth
Reth•3mo ago
Ah, it is connected to the cloned repo:
No description
Reth
Reth•3mo ago
Is it enough to just change the Repo here?
Brody
Brody•3mo ago
is that source repo correct?
Reth
Reth•3mo ago
Yep, it is the cloned one railway created where it uploaded the template code. it is a private repo though (ATM)
Brody
Brody•3mo ago
right but if its the template code, then its not your code so disconnect both the source and upsteam then connect the correct repo that contains your code
Reth
Reth•3mo ago
And in order to get it started do I have to create a requirements.txt as well as a Procfile too?
Brody
Brody•3mo ago
yes otherwise railway isnt going to know what to install or run
Reth
Reth•3mo ago
and is the root directory the root of the repo or where the .py files are in (Since it says "where we should look for your code")?
Brody
Brody•3mo ago
yes thats correct, you likely would not need to touch that
Reth
Reth•3mo ago
Can I also create the requirements.txt out of railway? Did not yet use one when being on replit.
Brody
Brody•3mo ago
the requirements.txt would need to exist within your github repo
Reth
Reth•3mo ago
I know. Just trying to get it created since so far was developing in the cloud. I will check back with replit to get it created there and then upload it into the repo.
Brody
Brody•3mo ago
saw that
Reth
Reth•3mo ago
sry will repost: Sry for asking all that nearly OT stuff: How are railway deployments working in general and in particular? Is there any documentation or good readup for this by chance? Would like to know a little bit about what is going on behind the curtain of all that magic. 🙂
Brody
Brody•3mo ago
heres a high level overview - https://docs.railway.app/maturity/philosophy#high-level-architecture but if you have any specfic questions i can do my best to answer them
Reth
Reth•3mo ago
Thank you very much. Maybe I will get back to this. Unfortunately the freeze on replit did not work entirely. The dotenv package is not listed in my requirements.txt nor is the os package. Now my bot fails with ModuleNotFoundError: No module named 'dotenv' Is there any default I can use or any other way to get this one solved?
Brody
Brody•3mo ago
dont use dotenv, its not needed on railway since the service variables are injected directly into the container and the os package is stdlib so that shouldn't be in the requirements.txt file anyway
Reth
Reth•3mo ago
oh IC. So accessing the variables via os.getenv("TOKEN") would be sufficient without importing anything?
Brody
Brody•3mo ago
you would still need to import os, but you would not need dotenv
Reth
Reth•3mo ago
sry next question already: I have a JSON data file in my data directory which is in parallel hierarchy to my .py file inside the src directory. But it cannot be found during loading. So this is how the directory structure looks like (screenshot). And this is how I try to access the JSON file within my .py file (2nd screenshot). But it can't be found. So in which directory is the running program looking for it? I.e. in which directory are we in when the application is started?
No description
No description
Reth
Reth•3mo ago
In the root since in Procfile it says: web: python src/cardBot.py?
Brody
Brody•3mo ago
you have not touched the root directory in the service settings right? can you share your repo so i can take a closer look?
Reth
Reth•3mo ago
sure - I can make it public maybe.... So here you are: https://github.com/RrTe/RedemptionCardBot
GitHub
GitHub - RrTe/RedemptionCardBot: Discord bot for the Redemption Car...
Discord bot for the Redemption Card Game. Contribute to RrTe/RedemptionCardBot development by creating an account on GitHub.
Brody
Brody•3mo ago
well you see, there is no json file in the data folder
Reth
Reth•3mo ago
Huh? I uploaded it. Just a sec .... Ouf! I forgot to commit the upload! Douh! Ok, so at least ../data/carddata.json can still be not found. Will try now with: data/carddata.json That seems to work - but now I am getting an error I never got before:
File "src/cardBot.py", line 51, in <module>
) -> list[app_commands.Choice[str]]:
TypeError: 'type' object is not subscriptable
File "src/cardBot.py", line 51, in <module>
) -> list[app_commands.Choice[str]]:
TypeError: 'type' object is not subscriptable
No clue whats wrong here. That code ran fine so far..
Brody
Brody•3mo ago
what version of python is replit running your code with?
Reth
Reth•3mo ago
3.10.13 So do I have to omit the -> part?
Brody
Brody•3mo ago
no, let's try getting railway to run your code with python 3.10 since 3.8 is the default
Reth
Reth•3mo ago
IC
Brody
Brody•3mo ago
add a runtime.txt file with 3.10 in it
Reth
Reth•3mo ago
in root directory? Finally I got it done! Great! Thank you so much! The bot is up and running now. So if I understand correctly it will be up and running there 24/7 now?
Brody
Brody•3mo ago
24/7 until you run out of credits, then you will need to upgrade to the hobby plan
Reth
Reth•3mo ago
what happens if I run out of credits? Will it be shut down or slowed down?
Brody
Brody•3mo ago
shut down
Reth
Reth•3mo ago
😦 too bad. But thank you again for your great help! Awesome!
Brody
Brody•3mo ago
why too bad? is the hobby plan not something you would be upgrading to when the time comes?
Reth
Reth•3mo ago
Need to check it out.