I want to store the amount of messages each user has sent in a json file. So everytime a user sends a message 1 to their amount in a json file. Then they can use a command to see how many messages they have sent. Im unsure how to do this as I am very unfamiliar with writing and reading to files.
CodePudding user response:
First, you would want to have an on message event.
Then, just open your json file, and add 1 to it. I would format it like so: {userid: messages}
CodePudding user response:
You can use the inbuilt json module -
import json
Messages=json.load(open('messages.json'))
And when you want to edit -
Messages[username] =1
json.dump(Messages,open('messages.json','w'))