我的代码:
@bot.command()
async def delwarn(ctx, member: discord.Member = None, warnid = None):
if member:
with open('warns.json', 'r') as fcheckifthere:
checkifthere = json.load(fcheckifthere)
if f'{member.id}' in checkifthere.keys():
amount = len(checkifthere[f'{member.id}'])
if f'{warnid}' in checkifthere[f'{member.id}']:
if not amount == 1:
# i want to delete the value f"{warnid}"
del checkifthere[f'{member.id}'][f'{warnid}']
with open('warns.json', 'w+') as fcheckifthere:
json.dump(checkifthere, fcheckifthere, sort_keys=True, indent=4)
错误:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: list indices must be integers or slices, not str
我想删除特定值 f"{warnid}",但我不知道如何删除此错误。
以下是 json 文件的示例:
{
305354423801217025: [
0145324124,
2142141244
]
{
泛舟湖上清波郎朗
相关分类