-2

I run my python bot, the server restarts, I start the python bot again, I want the python bot to resume from where it stopped before the server restarted, like create a paused file or something.

I'm using replit so the servers tend to restart periodically and it restarts from the beginning.

1 Answers1

0

This is a very broad question. What you could do is store information about the bot's state in a json file, an SQL database, etc..

Example:

import json

#variables
dict ProgramState = {
    "someInfo": "foo"
    "someInt": 56
    "someNames": ["adrian", "bob", "charlie"]
}


def save(savefilepath):
    out_file = open(savefilepath, "w") 
    json.dump(ProgramState, out_file, indent = 4)   
    out_file.close()

def load(loadfilepath):
    read_file = open(loadfilepath)
    ProgramState = json.load(read_file)
    read_file.close()

You should run save periodically, for example every time a command is called, and load whenever your program starts.

QWERTYL
  • 1,355
  • 1
  • 7
  • 11