Discord.py if语句/ json无法正常运行

时间:2018-07-18 19:14:33

标签: python json python-3.x discord.py

因此,我今天早些时候发表了一篇关于此的文章,并且我遵循了one of the answers,但仍然无法正常工作。

我有一个名为apps.json的文件,带有用户ID。

代码实际上总是跳转到声明用户没有帐户的语句,而实际上我却是。

它与balance命令一起使用,它第一次工作,然后停止工作,并告诉我一个地址已经存在,这意味着它反复使用相同的if语句,一次又一次创建一个帐户。

我遵循了其中一个答案,现在完全没有写入json。

代码:

@client.event
async def on_ready():
    with open('amounts.json') as f:
        old_amounts = json.loads(f)

    new_amounts = {}
    for d in old_amounts:
        for k, v in d:
            amounts[k] = amounts.get(k, 0) + v

    with open('amounts.json') as f:
        json.dump(amounts, f)
@client.command(pass_context=True)
async def balance(ctx):
    user_id = ctx.message.author.id
    global amounts
    if user_id not in amounts:
        block_io.get_new_address(label=user_id)
        knee = block_io.get_address_balance(label=user_id)
        s1 = json.dumps(knee)
        d2 = json.loads(s1)
        d2['data']['available_balance']
        embed=discord.Embed(description="Bitcoin: btc here \n\nLitecoin: here\n\nDogecoin: {}".format(d2['data']['available_balance']), color=0x00ff00)
        await client.say(embed=embed)
        with open('amounts.json', 'w+') as f:
            json.dump(amounts, f)
    elif user_id in amounts:
        knee = block_io.get_address_balance(label=user_id)
        s1 = json.dumps(knee)
        d2 = json.loads(s1)
        d2['data']['available_balance']
        embed=discord.Embed(description="Bitcoin: btc here \n\nLitecoin: here\n\nDogecoin: {}".format(d2['data']['available_balance']), color=0x00ff00)
        await client.say(embed=embed)
        with open('amounts.json', 'w+') as f:
            json.dump(amounts

编辑:

问题仍然没有解决。

0 个答案:

没有答案
相关问题