Python机器人游戏

时间:2018-09-25 23:36:37

标签: python-3.x discord.py

下面的代码在我使用!luck xx时工作正常,并且当金额低时会说金额低,但是当我使用!luck -xx时它仍会不断增加金额。
那么如何禁用-xx金额

@bot.command(pass_context=True)
async def luck(ctx, amounty: int):
    primary_id = ctx.message.author.id
    if primary_id not in amounts:
        await bot.say("not registered")
    elif amounts[primary_id] < amounty:
        await bot.say("low balance")
    else:
        amounts[primary_id] -= amounty
        a = random.randint(1,2)
        if a == 1:
            amounts[primary_id] += amounty * 2
            await bot.say("You Won")
        else:
            await bot.say("You lost")

1 个答案:

答案 0 :(得分:1)

只需检查数字是否为负数,如果为负则返回空值

  if amounty<0:
    await bot.say("Can't use a negative number")
    return