Discord.py Railway json
lightdever
TRIALOP

2 years ago

I use discord.py and use json file to save user informations but it doesn't work in railway how can I solve this issue?

Solved

31 Replies

lightdever
TRIALOP

2 years ago

N/A


2 years ago

You store data in a json file? That's so based I used to do that

Althouh I'd recommend just using a database, it's much easier that way. If you have to use a json file though then store it within a volume , that way the data will persist between deployments

Anyway, what doesn't work about it?


lightdever
TRIALOP

2 years ago

So it stores it in the volume but I think the bot.py can't modify the json files so when we restart it rollbacks


2 years ago

If there was a permission issue regarding writing to the file then I'm sure python would've wrote an error

are you sure you have the volume mounted on the correct location?

if your app stores the json file in /data then you might have to mount the volume to /app/data


2 years ago

(assuming you're using nixpacks)


lightdever
TRIALOP

2 years ago

i'll try


lightdever
TRIALOP

2 years ago

it wont work 😦


lightdever
TRIALOP

2 years ago

WORD_DATA_FILE = os.path.join(BASE_DIR, "word_data.json")
BALANCE_DATA_FILE = os.path.join(BASE_DIR, "bankbalance.json")
ATTENDANCE_DATA_FILE = os.path.join(BASE_DIR, "attendance.json")
HISTORY_DATA_FILE = os.path.join(BASE_DIR, "history.json")

lightdever
TRIALOP

2 years ago

Does this kind of don't work in railway?


lightdever
TRIALOP

2 years ago

Is there another solution?


lightdever
TRIALOP

2 years ago

Just a want to way to save informations


lightdever
TRIALOP

2 years ago

If possible with json


2 years ago

what's your current volume mount path?


lightdever
TRIALOP

2 years ago

don't have any


lightdever
TRIALOP

2 years ago

is volume for saving files like json?


2 years ago

a volume is for saving any files


lightdever
TRIALOP

2 years ago

ahh


lightdever
TRIALOP

2 years ago

what path do i need to set my volume?


2 years ago

fragly has previously covered that question


lightdever
TRIALOP

2 years ago

ok


lightdever
TRIALOP

2 years ago

1341289389325549579


lightdever
TRIALOP

2 years ago

It would just load the files that is saved in github and don't save


lightdever
TRIALOP

2 years ago

Volume is in /data


lightdever
TRIALOP

2 years ago

BASE_DIR = os.path.dirname(os.path.abspath("/data"))

WORD_DATA_FILE = os.path.join(BASE_DIR, "word_data.json")

BALANCE_DATA_FILE = os.path.join(BASE_DIR, "bankbalance.json")

ATTENDANCE_DATA_FILE = os.path.join(BASE_DIR, "attendance.json")

HISTORY_DATA_FILE = os.path.join(BASE_DIR, "history.json")


2 years ago

you would want to add logging to print those paths to make sure they are correct


lightdever
TRIALOP

2 years ago

ok


2 years ago

<:bruhdy:1330634189283917855>


lightdever
TRIALOP

2 years ago

I'll figure it out with db because json is too old thank you for helping 😄


2 years ago

@Fragly solve time


2 years ago

Oh true, thank you!


2 years ago

!s


Status changed to Solved dev • over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...