【问题标题】:Discord.py if statements for some reason will not work..?Discord.py if 语句由于某种原因将不起作用..?
【发布时间】:2019-01-10 06:11:00
【问题描述】:

所以,我有以下代码。

@client.command(pass_context=True)
async def tip(ctx, amount: int, other: discord.Member):
    id = ctx.message.author.id
    other_id = other.id
    if id in ids:
        maddy = block_io.get_address_balance(label=id)
        oaddy = block_io.get_address_balance(label=other_id)
        s1 = json.dumps(maddy)
        d2 = json.loads(s1)
        s2 = json.dumps(oaddy)
        d3 = json.loads(s2)
        d2['data']['available_balance']
        d3['data']['available_balance']

        if float(d2['data']['available_balance']) > amount:
            if amount > 2:
                embed=discord.Embed(description="Tip Sent! **-1 Fee Deducted**", color=0x00ff00)
                await client.say(embed=embed)
                block_io.withdraw_from_labels(amounts=amount, from_labels=id, to_labels=other_id)
            else:
                embed=discord.Embed(description="Tipping requires you to have at least 2 Doge. **1 is deducted for fees.**", color=0x00ff00)
                await client.say(embed=embed)

            #embed=discord.Embed(description="", color=0x00ff00)
            #await client.say(embed=embed)
        else: #less then 
            embed=discord.Embed(description="**You dont have enough to tip!**", color=0x00ff00)
            await client.say(embed=embed)
            with open("ids.txt", "a") as f:
                print(id, file=f)
    else:
        block_io.get_new_address(label=id)
        block_io.get_address_balance(label=id)
        maddy = block_io.get_address_balance(label=id)
        oaddy = block_io.get_address_balance(label=other_id)
        s1 = json.dumps(maddy)
        d2 = json.loads(s1)
        s2 = json.dumps(oaddy)
        d3 = json.loads(s2)
        d2['data']['available_balance']
        d3['data']['available_balance']

        if float(d2['data']['available_balance']) > amount:
            if amount > 2:
                embed=discord.Embed(description="Tip Sent! **-1 Fee Deducted**", color=0x00ff00)
                await client.say(embed=embed)
                block_io.withdraw_from_labels(amounts=amount, from_labels=id, to_labels=other_id)
            else:
                embed=discord.Embed(description="Tipping requires you to have at least 2 Doge. **1 is deducted for fees.**", color=0x00ff00)
                await client.say(embed=embed)

            #embed=discord.Embed(description="", color=0x00ff00)
            #await client.say(embed=embed)
        else: #less then 
            embed=discord.Embed(description="**You dont have enough to tip!**", color=0x00ff00)
            await client.say(embed=embed)
            with open("ids.txt", "a") as f:
                print(id, file=f)
    with open("ids.txt", "a") as f:
        print(id, file=f)

当我运行命令时,我会尝试给没有帐户的人小费。然而,它没有执行 else 语句,而是转到 if 语句,并产生错误。我希望它转到 else 语句,但即使用户 id 不在 ids 中也不会。

Ignoring exception in command tip
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "index.py", line 89, in tip
    oaddy = block_io.get_address_balance(label=other_id)
  File "/usr/local/lib/python3.6/site-packages/block_io/__init__.py", line 168, in hook
    return self.api_call(attr, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/block_io/__init__.py", line 290, in api_call
    raise BlockIoAPIError('Failed: '+response['data']['error_message'])
block_io.BlockIoAPIError: Failed: One or more addresses or labels do not exist on your account for Network=DOGE, or are invalid for Network=DOGE.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: BlockIoAPIError: Failed: One or more addresses or labels do not exist on your account for Network=DOGE, or are invalid for Network=DOGE.
Ignoring exception in command tip
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "index.py", line 89, in tip
    oaddy = block_io.get_address_balance(label=other_id)
  File "/usr/local/lib/python3.6/site-packages/block_io/__init__.py", line 168, in hook
    return self.api_call(attr, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/block_io/__init__.py", line 290, in api_call
    raise BlockIoAPIError('Failed: '+response['data']['error_message'])
block_io.BlockIoAPIError: Failed: One or more addresses or labels do not exist on your account for Network=DOGE, or are invalid for Network=DOGE.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: BlockIoAPIError: Failed: One or more addresses or labels do not exist on your account for Network=DOGE, or are invalid for Network=DOGE.

我错过了什么?

【问题讨论】:

  • 不要发送垃圾短信来填补您的问题!

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


【解决方案1】:

这是失败的行:

oaddy = block_io.get_address_balance(label=other_id)

请注意,这存在于您的 ifelse 块中。如果 other 人没有帐户,您没有任何关于该做什么的逻辑,只有当调用命令的人没有帐户时。您需要在某个时候检查if other_id in ids:

【讨论】:

  • other.id?骗局?
  • @Zatbot 我不明白这个问题
  • 是other.id吗?
  • 是什么other.id
  • 不是 other_id 是 other.id
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多