在我的机器人上,我继续使用我的声明命令,但它一直让机器人在def claimer中发布两条消息。这是代码:
def claimer(user, name, room):
if user.lower() == name.lower():
room.message("Pfft. You can't catch yourself.")
elif name.lower() not in room.usernames:
room.message("You can't capture %s they are not here." % name.title())
else:
if not user in claim.claimDB:
claim.claimDB[user] = []
num = len(claim.claimDB[user])
if claim.limit(num) == True:
room.message("You have reached your limit on captures %s. You must release some people in order to catch %s" % (user.title(), name.title()))
else:
for a, b in claim.claimDB.items():
if name.lower() in b:
room.message("%s has already been caught by %s." % (name.title(), a.title()))
else:
escapechance = random.choice([True,True,True,False])
if escapechance == True:
claim.claimDB[user] = claim.claimDB[user]+[name]
room.message("//Pokeball wiggles three times before stopping// You have successfully captured %s! \o/" % name.title()) <----this message.
else:
room.message("Failed to capture them")<----- this one too at the same time.
在claim.claimDB.items()中的for a,b:如果b:中的name.lower()是为了防止同一名称出现在claim.claimDB.items()中的b中,而是导致那些弹出两条消息并再次在文件中放置相同的名称。