Json Edit From Bot
When the desired numbers are written with the test command, it passes to json.
then using the test1 command, number3 needs to change but the whole line is changing
@bot.command() async def test(ctx, number1: str, number2: str, number3: str): with open('data/data.json', 'r') as f: data = json.load(f) data[str(ctx.guild.id)] = { 'number1': number1, 'number2': number2, 'number3': number3 } with open('data/data.json', 'w') as f: json.dump(data, f, indent=4) @bot.command() async def test1(ctx, number1: str): with open('data/data.json', 'r') as f: data = json.load(f) data[str(ctx.guild.id)] = { 'number1': number1 } with open('data/data.json', 'w',)as f: json.dump(data, f, indent=4)
This code:
data[str(ctx.guild.id)] = { 'number1': number1 }
will assign a new dictionary, { 'number1': number1 }
, to that "714235..."
field of data
, so the original dictionary (that contained number1, number2, number3
) will be gone and garbage collected.
Did you mean to change the single "number1"
key?
data[str(ctx.guild.id)]['number1'] = number1