Я некоторое время боролся с этой командой. Я могу заставить один чек работать, но не другой. Я хочу убедиться, что пользователь не может упомянуть себя И что он не может "ограбить" другого пользователя, если у него меньше $ 0, получаемого из get_dollars. Я попытался "try, except, else, finally"
и получил его на половину работы, но он выложил бы два сообщения вместо одного. Затем я попробовал приведенный ниже код, подумав, если бы я вложил if
и else
утверждения, что это будет работать лучше. Я получаю ошибку if message.author == user.mention: UnboundLocalError: local variable 'user' referenced before assignment
, пытающуюся таким образом.
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))