Question: I'm working on a more advanced leveling system. I want a user on any server as long as they are an administrator to be able to change the XP amount. I'm using a value in my server database to achieve that. Every time it makes an edit for that command, I've noticed that it truncates the entire file and applies the edits. I've used the same 5 lines to do this, and it just started not to work. The other command I used for toggling the level system worked perfectly fine, even with the same 5 lines. I even tried setting the value that was getting changed to another one, and it still had the same issue, so it can't be the value's problem. Does anyone know how to fix this issue? Please and thanks :) its really annoying to stand Code @levelmds.command(name="set_xp_addition", description="Choose how many XP you want to give to your members. Set 0 or blank to go to the default. (4)") async def setxpaddition(interaction: discord.Interaction, xp: int = 0): with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) if str(interaction.guild.id) in data: if not interaction.user.guild_permissions.administrator: await interaction.response.send_message(f":x: Only administrators of {interaction.guild.name} can execute this command.") else: if xp: if xp == 0: with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) data[str(interaction.guild.id)]['xpaddition'] = 0 with open("database\\wae.json", "w+") as fa: json.dump(data, fa) await interaction.response.send_message("✅ Successfully set XP addition to the default (4)") else: with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) data[str(interaction.guild.id)]['xpaddition'] = xp with open("database\\wae.json", "w+") as fa: json.dump(data, fa) await interaction.response.send_message(f"✅ Successfully changed XP addition to **{xp}.**") else: with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) data[str(interaction.guild.id)]['xpaddition'] = 0 with open("database\\wae.json", "w+") as fa: json.dump(data, fa) await interaction.response.send_message("✅ Successfully set XP addition to the default (4)")  (btw this command is in a GROUP, so for testing consider changing levelmds to bot.tree.command.)

Answer: First of all, the code in the if statement on the line 10 is unreachable cause 0 is evaluated as false, so the if statement on the line 9 is only fulfilled when xp is not 0. Here is the code simplified: @levelmds.command(name="set_xp_addition", description="Choose how many XP you want to give to your members. Set 0 or blank to go to the default. (4)") async def setxpaddition(interaction: discord.Interaction, xp: int = 0): with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) if str(interaction.guild.id) in data: if not interaction.user.guild_permissions.administrator: await interaction.response.send_message(f":x: Only administrators of {interaction.guild.name} can execute this command.") else: if xp != 0: with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) data[str(interaction.guild.id)]['xpaddition'] = xp with open("database\\wae.json", "w+") as fa: json.dump(data, fa) await interaction.response.send_message(f"✅ Successfully changed XP addition to **{xp}.**") else: with open("database\\wae.json", encoding="utf-8") as f: data = json.load(f) data[str(interaction.guild.id)]['xpaddition'] = 0 with open("database\\wae.json", "w+") as fa: json.dump(data, fa) await interaction.response.send_message("✅ Successfully set XP addition to the default (4)")  And about the problem of the file being truncated and wrote with the modifications, when using w+ the existing content in the file is cleared so that's why it gets erased. This is necessary to dump the new data to the file, but if many users in many servers are using the command, maybe you are going to lose data.