2
@commands.command()
        data = {}
        data[f'intros'] = []

        await ctx.send("**Let's create your intro...**")
        await ctx.send("What's your name?")
        name = await self.client.wait_for('message', check=lambda message: message.author == ctx.author)
        await ctx.send("How old are you?")
        age = await self.client.wait_for('message', check=lambda message: message.author == ctx.author)
        await ctx.send("Where are you from?")
        location = await self.client.wait_for('message', check=lambda message: message.author == ctx.author)
        await ctx.send("What about your interests?")
        interests = await self.client.wait_for('message', check=lambda message: message.author == ctx.author)

        
        data['intros'][f'{ctx.author.id}']
            {
                'name': f'{name.content}',
                'age': f'{age.content}',
                'location': f'{location.content}',
                'interests': f'{interests.content}'
            }
        })
    
    with open('./cogs/intros.json', 'w') as outfile:
            json.dump(data, outfile, indent=4)

{
    "intros": [
        {
            "813285103757295666": {
                "name": "a",
                "age": "b",
                "location": "c",
                "interests": "d"
            }
        }
    ]
}

I'm creating a discord.py bot and I'm trying to create an intro system so that it will store the values in a json file(intro.json). The values are stored using the user id. When I execute the command it stores the values as I needed but when another user executes it, it overwrites the existing values.

I want it to create separate dicts everytime a user executes the command. How do I do so?

Arya McCarthy
  • 8,554
  • 4
  • 34
  • 56
Yeti
  • 155
  • 10

1 Answers1

1

Someone already commented something similar, but I thought I'd expand. What I'd do is load the JSON data, add to the intros array, and then rewrite the JSON file with the updated data.

Dharman
  • 30,962
  • 25
  • 85
  • 135