Reputation: 166
I made a "disable module" which is working, but when it loads into a json file I get a error message.
@client.command(aliases=["disable economy"])
async def disable_economy(message):
with open('disable economy.json', 'r+') as f:
channel = json.load(f)
if not f'{message.channel.id}' in channel:
channel[f'{message.channel.id}'] = "Channel ID"
json.dump(channel, f)
await message.channel.send(f"Economy has been disabled in <#{message.channel.id}>. ")
return
if f'{message.channel.id}' in channel:
await message.channel.send("Economy is already disabled in this channel.")
return
After doing the command it loads into a json file like this:
{}{"750485129436201023": "Channel ID"}
and the error message I get is: End of file expected
. The error is between the 2nd {. Can someone help?
Upvotes: 0
Views: 244
Reputation: 1356
{}{"750485129436201023": "Channel ID"}
is not valid JSON.
Valid JSON can only have one root element, such as {}
Change your JSON file to just:
{"750485129436201023": "Channel ID"}
Python is appending to the file, instead of overwriting it, the easiest way to fix this is to seek
to the beginning of the file before writing:
f.seek(0)
json.dump(channel, f)
Upvotes: 1