我一直在努力解决这个问题。我可以得到一张支票,但不能另外支票。我想确保用户不能提及自己并且如果他们从get_dollars中提取的资金少于0美元,他们就不能“抢劫”另一个用户。我已经尝试过"try, except, else, finally"
并让它进行半工作但它会吐出两条消息而不是一条消息。然后我尝试下面的代码思考,如果我嵌套if
和else
语句,它会更好地工作。我得到一个if message.author == user.mention: UnboundLocalError: local variable 'user' referenced before assignment
error尝试这种方式。
if message.content.startswith('!rob'):
if message.author == user.mention:
await client.send_message(message.channel, "{} you cant rob yourself! 👊".format(message.author.mention))
else:
if get_dollars(message.author) < 0:
await client.send_message(message.channel, "{} you can't even afford a gun.".format(message.author.mention))
else:
for user in message.mentions:
if (get_dollars(user)) < 1:
await client.send_message(message.channel, "{} is too broke to rob 🤣".format(user.mention))
elif steal <= 3:
print("{} catches {} slippin and sticks them up for ${} 😨🔫".format(message.author.mention, user.mention, stealdollars))
await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} 😨🔫".format(message.author.mention, user.mention, stealdollars))
remove_dollars(user, stealdollars)
add_dollars(message.author, stealdollars)
elif steal == 4:
print("{} gets arrested trying to rob {} and has to post $250 bail 👮🚨".format(message.author.mention, user.mention))
await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post $250 bail 👮🚨".format(message.author.mention, user.mention))
remove_dollars(message.author, 250)
elif steal >= 5:
print("{} kicks {}'s door down but doesn't find any cash 🤬".format(message.author.mention, user.mention))
await client.send_message(message.channel, "{} kicks {}'s door down but doesn't find any cash 🤬".format(message.author.mention, user.mention))
就像帕特里克所说的那样,没有用户的定义。结束put user = message.mentions [0],命令正常。