JSON文件加载不正确



由于某些原因,当我用Import Json加载字典时,它不起作用。它可以打印字典,但当我搜索现有的关键字时,它就像没有一样。

with open('exp.json') as w:
exp = json.load(w)
print(exp)
with open('levels.json') as q:
levels = json.load(q)
@bot.command(aliases = ['rank'])
async def level(ctx):
if ctx.author.id in exp:
await ctx.send(f"You Are Level {levels[ctx.author.id]}")

我做错了什么吗?

我假设您在(exp.json(文件中有用户id作为主键。

然后你应该试试这个程序

with open('exp.json') as w:
exp = json.load(w)
print(exp)
with open('levels.json') as q:
levels = json.load(q)
@bot.command(aliases = ['rank'])
async def level(ctx):
if str(ctx.message.author.id) in exp.keys():
await ctx.send(f"You Are Level {levels[str(ctx.message.author.id)]}")

最新更新