I 'm using repl.it to run my discord bot but I have encountered a problem. Sometimes, at the end of the day usually, whatever the users did does not save in the json file assigned to store the data. Does anyone know what is happening?
Asked
Active
Viewed 438 times
2 Answers
0
Hey i have had the same problem and it is because file changes do not persist if you are not in the editor.
The best thing you could do is use a database to store your data.
Take a look at some databases like mongo db and PostgreSQL.

Alpha
- 319
- 2
- 12
0
I have found a fix to this problem. Apparently, repl.it enforced this feature due to DDos attack occurring, I'm not really sure what happened but it was a security feature. To save the file, even when I'm not on the editor (which was causing the problem) I have to make my script open the file and then close it, saving it. Here's how I did that:
def save(filePath="filename.json", **kwargs):
while True:
with open(filePath, "w") as f:
f.write(json.dumps(kwargs))
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Streaming(
name=f"+help - {len(bot.guilds)} servers - dsc.gg/wumpusbot",
url="https://www.twitch.tv/defaultmodels"))
print('Bot is online')
await save()

DefaultModels.exe
- 46
- 1
- 9