Discord Bot not working - Command not found

AnonymousTRIAL

a year ago

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!

0 Replies

AnonymousTRIAL

a year ago

Project ID: 8c1db389-9532-4ead-9ee9-2f4b19a5334c


a year ago

if you deployed the template then you arent running your code, you would be running the template's code


AnonymousTRIAL

a year ago

Hmm, but I had to connect my repo for it. How can I get this solved to let it run my code?


a year ago

show me a screenshot of the source in your service settings please


AnonymousTRIAL

a year ago

Ah, it is connected to the cloned repo:

1219773095724847400


AnonymousTRIAL

a year ago

Is it enough to just change the Repo here?


a year ago

is that source repo correct?


AnonymousTRIAL

a year ago

Yep, it is the cloned one railway created where it uploaded the template code.


AnonymousTRIAL

a year ago

it is a private repo though (ATM)


a year ago

right but if its the template code, then its not your code


a year ago

so disconnect both the source and upsteam then connect the correct repo that contains your code


AnonymousTRIAL

a year ago

And in order to get it started do I have to create a requirements.txt as well as a Procfile too?


a year ago

yes otherwise railway isnt going to know what to install or run


AnonymousTRIAL

a year 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")?


a year ago

yes thats correct, you likely would not need to touch that


AnonymousTRIAL

a year ago

Can I also create the requirements.txt out of railway? Did not yet use one when being on replit.


a year ago

the requirements.txt would need to exist within your github repo


AnonymousTRIAL

a year 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.


AnonymousTRIAL

a year ago

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. 🙂


a year ago

saw that


AnonymousTRIAL

a year ago

sry


AnonymousTRIAL

a year ago

will repost:


AnonymousTRIAL

a year ago

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. 🙂


a year ago

heres a high level overview -
but if you have any specfic questions i can do my best to answer them


AnonymousTRIAL

a year 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?


a year ago

dont use dotenv, its not needed on railway since the service variables are injected directly into the container


a year ago

and the os package is stdlib so that shouldn't be in the requirements.txt file anyway


AnonymousTRIAL

a year ago

oh IC. So accessing the variables via os.getenv("TOKEN") would be sufficient without importing anything?


a year ago

you would still need to import os, but you would not need dotenv


AnonymousTRIAL

a year 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?

1219781891134197800
1219781891431862300


AnonymousTRIAL

a year ago

In the root since in Procfile it says: web: python src/cardBot.py?


a year ago

you have not touched the root directory in the service settings right?


a year ago

can you share your repo so i can take a closer look?


AnonymousTRIAL

a year ago

sure - I can make it public maybe…. So here you are: https://github.com/RrTe/RedemptionCardBot


a year ago

well you see, there is no json file in the data folder


AnonymousTRIAL

a year ago

Huh? I uploaded it. Just a sec ….


AnonymousTRIAL

a year ago

Ouf! I forgot to commit the upload! Douh!


AnonymousTRIAL

a year ago

Ok, so at least ../data/carddata.json can still be not found. Will try now with: data/carddata.json


AnonymousTRIAL

a year ago

That seems to work - but now I am getting an error I never got before:

File "src/cardBot.py", line 51, in ) -> list[app_commands.Choice[str]]: TypeError: 'type' object is not subscriptable


AnonymousTRIAL

a year ago

No clue whats wrong here. That code ran fine so far..


a year ago

what version of python is replit running your code with?


AnonymousTRIAL

a year ago

3.10.13


AnonymousTRIAL

a year ago

So do I have to omit the -> part?


a year ago

no, let's try getting railway to run your code with python 3.10 since 3.8 is the default


AnonymousTRIAL

a year ago

IC


a year ago

add a runtime.txt file with 3.10 in it


AnonymousTRIAL

a year ago

in root directory?


AnonymousTRIAL

a year ago

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?


a year ago

24/7 until you run out of credits, then you will need to upgrade to the hobby plan


AnonymousTRIAL

a year ago

what happens if I run out of credits? Will it be shut down or slowed down?


a year ago

shut down


AnonymousTRIAL

a year ago

😦 too bad. But thank you again for your great help! Awesome!


a year ago

why too bad?


a year ago

is the hobby plan not something you would be upgrading to when the time comes?


AnonymousTRIAL

a year ago

Need to check it out.


Discord Bot not working - Command not found - Railway Help Station