0

I am using Vultr VPS to host my discord bot. The bot works fine except for the fact that it cannot store data in JSON files, which is a big part of the bot. When I attempt to open a JSON file using with open, I receive the error No such file or directory. I have already imported JSON and doubled checked the file location. Opening JSON files has worked fine when running off my computer and in replit.com. For some reason, in Vultr, it is unable to find the file. I am using discord.py as my library.

My Linux VPS is Ubuntu.

Here is the tree of my directory:

 .                                                                                                                      
 └── bot                                                                                                                     
     ├── bot.py                                                                                                              
     └── storage                                                                                                                 
         ├── open.json                                                                                                           
         ├── prefix.json                                                                                                         
         ├── questions.json                                                                                                      
         ├── server.json                                                                                                         
         └── tags.json   
                                                                                                                                                                                                                        
2 directories, 6 files                                                                                                  

Do I have to define the file from the root of the directory? So far, in bot.py, I have tried:

with open("/storage/prefix.json") as f:

and

with open("~/bot/storage/prefix.json") as f:

I appreciate any help or tips. If you'd like to see more code, please let me know! Thanks in advance!

Bob Brown
  • 92
  • 12
  • Your first method doesnt work because storage is not under root, and second method doesn't work because you need to expand the ~ path (assuming your "." means the home dir). Either use the absolute path (by expanding home or typing it out), or use relative path as seen in the dupe post. – Taku Oct 25 '21 at 23:51

0 Answers0