@bot.command()
async def delpartner(ctx, amount: typing.Optional[int]):
with open("config.json", "r") as jsonFile:
data = json.load(jsonFile)
del data[amount]
json.dump(jsonFile)
await ctx.send("Партнёр успешно удалён!")
{
"users": [
{
"id": 1,
"name": "test"
},
{
"id": 2,
"name": "test2"
}
]
}
del data[amount]
Command raised an exception: KeyError: '2'
#
with open('config.json', 'rb') as fp:
jsondata = json.load(fp)
objF = json.load(open("config.json"))
jsondata = [objF for objF in jsondata if objF['partners'] != args]