with open("data/tickets.json", "r") as f:
data = json.load(f)
data[str(ticket.id)]["author"] = ctx.author.id
with open("data/tickets.json", "w") as f:
json.dump(data, f, indent=4)
I want to create in a json file, the ticket id and the author of this ticket. But i want it looks so:
{
"random_channel_id" {
"author": "random_user_id"
}
}
But its give me this error:
Traceback (most recent call last):
File "C:\Users\omalo\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 383, in _run_event
await coro(*args, **kwargs)
File "C:\Users\omalo\OneDrive\Desktop\Home Bot\cogs\Ticket.py", line 46, in TicketCreation
data[str(ticket.id)]["author"] = ctx.author.id
KeyError: '995020823683412029'
data[str(ticket.id)]["author"] = ctx.author.idwould work if you have an existingstr(ticket.id)and you want to add (or change) "author" in it. The error tells you it doesn't exist in this case. But, is this always the case? Are you trying to update an existing entry?