Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I save every user to the json file in discord?

The code I have at the moment doesn’t accompany for all users as the json file which it stores the "coins" in only saves it as userid. This is the code for storing the coins in the json file:

@client.command()
async def Shibaku1(ctx, coin1, coin2, coin3, coin4, coin5, coin6):
  with open('Shibaku1.json', 'r') as f:
    coins_data = json.load(f)
  coins_data['userid'] = (coin1, coin2, coin3, coin4, coin5, coin6)
  with open('Shibaku1.json', 'w') as f:
    json.dump(coins_data, f)

Example of what gets stored in the json file:

{"userid": [":Helicopter:", ":Skateboard1:", ":swords:", ":mace:", ":mace:", ":mangosteen:"]}

How do I make it so it stores a different set for each user?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace coins_data['userid'] with coins_data[ctx.author.id].

Then your json file will look like this:

{123456789: [":Helicopter:", ":Skateboard1:", ":swords:", ":mace:", ":mace:", ":mangosteen:"]}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading