我的代码有一个很大的问题,在过去的3个小时里我在互联网上找不到任何东西,所以我在这里询问。我试图将ctx.guild.id作为一个新变量添加到我的json“queue.json”文件中,但显然每次运行此代码时,它都会覆盖先前添加的变量,而不是在新行中添加一个新变量。这是我的密码:
with open("queue.json", "r") as f:
Queue = json.load(f)
if not ctx.guild.id in Queue:
with open("queue.json", "w") as QueueAddFile:
NewQueueID = {ctx.guild.id : []}
json.dump(NewQueueID, QueueAddFile, separators=(',', ':'))
您没有将密钥添加到
Queue
字典,而是创建了一个新字典,其中只有一个新ID。因此,当您重写文件时,您将丢弃所有其他密钥相关问题 更多 >
编程相关推荐