【发布时间】:2018-07-18 14:47:19
【问题描述】:
我有这段代码(Python 3.6),它应该这样做,如果用户有一个钱包,然后显示余额。如果他们没有钱包,请创建一个钱包并出示余额。
我有一个名为 amount.json 的文件,其中包含用户 ID。
代码总是跳转到它说用户没有帐户的语句,而实际上我有,并给我错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: BlockIoAPIError: Failed: Label already exists on your account for Network=DOGE.
我该如何解决它,使它不会在我每次执行余额命令时都尝试制作钱包?
代码:
@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, f)
Json 代码:
amounts = {}
@client.event
async def on_ready():
global amounts
try:
with open('amounts.json') as f:
amounts = json.load(f)
except FileNotFoundError:
print("Could not load amounts.json")
amounts = {}
【问题讨论】:
-
显示将
amounts.json加载到amounts变量中的代码。另外,block_io是什么?这就是你的错误所在。 -
block_io 是一个区块链钱包 @PatrickHaugh 我现在用 json 代码更新它
-
您能否也显示来自 amount.json 文件的条目?还要检查
print(discord.__version__)以查看您使用的是哪个版本的 discord.py。在某些版本中,ids 是字符串,但在最近的版本中,它们是整数。 -
版本为 0.16.12
-
输入为:
标签: python python-3.x discord.py