json - 不和谐.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}
解决方案
根据编辑的amounts
字典,您没有保存 JSON 文件。
推荐阅读
- amazon-web-services - boto3 将过滤后的存储桶中的所有键作为列表获取
- javascript - 对象不会使用 react-hook-form 附加到字段数组
- git - 突出显示单词并从 CMD 中删除?
- c# - 如何补救“循环或多级联路径”?
- angular - Angular 9 - 带有静态对象的补丁值
- java - 没有 Maven/Gradle 的 Java REST API 框架
- python - Pygame像素完美碰撞没有按预期工作
- sql - 具有 2 个 Like 参数的存储过程
- postgresql - Postgres 主从平衡器
- date - 如何在 Discord.js v12 中将日期格式化为 DD/MMM/YYYY