首页 > 解决方案 > 不和谐.PY JSON

问题描述

所以我在做一些事情,奇怪的事情正在发生。我的 amount.json 正在重置,并且代码没有添加到 amount.json。(例如,我键入添加到数字的命令,但它对 amount.json 没有任何作用)

代码:

@bot.command(pass_context=True)
async def redeem(ctx, key):
    with open('amounts.json') as f:
     amounts = json.load(f)
    id = int(ctx.message.author.id)
    if key in amounts:
      if amounts[key] < int(2):
       await ctx.send("You have been given Buyer role!")
       amounts[key] += int(1)
       member = ctx.message.author
       this_guild = member.guild

       role = get(member.guild.roles, name='Buyer')
       await member.add_roles(role)
       Message = ctx.message
       await Message.delete()
       await ctx.send("You have been given Buyer role!")
       _save()
      else:
        await ctx.send("Invalid Key!")

    else:
        await ctx.send("Invalid Key!")

JSON

{"196430670": 0}

标签: jsondiscord.py

解决方案


根据编辑的amounts字典,您没有保存 JSON 文件。


推荐阅读