我对python有点陌生,但是我知道像变量和字符串之类的基础知识,最近我创建了一个带有货币和商店的discord机器人。这家商店不营业,是为了让我买列出的物品的票(不是要存放任何东西)。请您帮我找出我出了什么问题,并帮助我改善或让我看看我哪里出错了,哪里可以找到我的答案。这是我在商店买到的东西(请注意我正在使用python 3.6.4):
@client.command(pass_context = True)
async def buy(ctx, item):
items = {
"Apex Legends":[3,20],
"Minecraft":[5,30],
"Halo":[5,20],
"Fortnite":[8,10],
}
while True:
print("Apex Legends = 3BP / Minecraft = 5BP / Halo = 5BP / Fortnite = 8BP")
print("Account Balance bp",stash)
choice = input("What would you like to buy?: ").strip().title()
if choice in items:
if items[choice][1]>0:
if stash>=items[choice][0]:
items[choice][1]=items[choice][1]-1
stash= stash-items[choice][0]
print("Thank you..!")
print("")
else:
print("Sorry you don\'t enough money...")
print("")
else:
print("sorry sold out")
print("")
else:
print("Sorry we don\'t have that item...")
print("")
如果您想在bot上看到我的完整代码,请点击此处: https://hastebin.com/tojadefajo.py
答案 0 :(得分:0)
while True:
,因为您没有break
语句,这将进入无限循环! print()
语句替换所有await client.say()
语句尝试一下
@client.command(pass_context = True)
async def buy(ctx, item):
items = {
"Apex Legends": [3, 20],
"Minecraft": [5, 30],
"Halo": [5, 20],
"Fortnite": [8, 10],
}
await client.say("Apex Legends = 3BP / Minecraft = 5BP / Halo = 5BP / Fortnite = 8BP")
await client.say("Account Balance bp", stash)
choice = input("What would you like to buy?: ").strip().title()
if choice in items:
if items[choice][1]>0:
if stash>=items[choice][0]:
items[choice][1]=items[choice][1]-1
stash= stash-items[choice][0]
await client.say("Thank you..!")
await client.say("")
else:
await client.say("Sorry you dont enough money...")
await client.say("")
else:
await client.say("sorry sold out")
await client.say("")
else:
await client.say("Sorry we don't have that item...")
await client.say("")