Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Recently, I've been making a fun server specific discord bot for me and my friends. (Using discord.py). Because I need to turn off my computer at night, I cannot run my bot continuously on my PC. I decided to make a GitHub repository and deploy it to a service called Heroku, that way it is guaranteed to run without my supervision.

That's where my problems start. I have a point system that dumps the user's ID along with the points awarded to them in a file I named data.txt. The file has not been updating since then. I suspect it is because you must commit to the file in order to alter it in anyway.

What I have tried:

I went down a massive rabbit hole, learning about committing files via python. By importing py.discord, you can alter your code from there. HOWEVER! No articles ever mention editing a file. Rather, they commit new files or completely replace them! Maybe I can have the bot copy and paste the current data and add the new user IDs, and then add them together. But I'm unaware if that's possible. Here's a command I assigned to "_save()":
def _save():
    with open('data.txt', 'w+') as f:
        json.dump(points, f)

Anyone know how I can implement it? Documents on py.github: Introduction — PyGithub 1.55 documentation[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900