【发布时间】:2021-11-24 18:56:24
【问题描述】:
我不知道我做错了什么来得到这个错误......因为我已经等待了应该等待的事情,除非我没有而且我似乎看不到它?虽然说在我还没用的时候就在更新银行功能上,而且这个错误只有在使用这个命令的时候才会出现。
代码如下:
async def use_this(user,item_name,amount,price = None):
item_name = item_name.lower()
name_ = None
for item in mainshop:
name = item["name"].lower()
if name == item_name:
name_ = name
if price==None:
price = 0* item["price"]
break
if name_ == None:
return [False,1]
cost = price*amount
users = await get_bank_data()
bal = await update_bank(user)
try:
index = 0
t = None
for thing in users[str(user.id)]["bag"]:
n = thing["item"]
if n == item_name:
old_amt = thing["amount"]
new_amt = old_amt - amount
if new_amt < 0:
return [False,2]
users[str(user.id)]["bag"][index]["amount"] = new_amt
t = 1
break
index+=1
if t == None:
return [False,3]
except:
return [False,3]
with open("mainbank.json","w") as f:
json.dump(users,f)
await update_bank(user,cost,"wallet")
return [True,"Worked"]
@client.command()
async def hunt(ctx,item = ['rifle','Rifle'],amount = 1):
user = ctx.author
users = await get_bank_data()
res = await use_this(ctx.author,item,amount)
rifle = "rifle"
if amount > 1:
await ctx.reply("You cant use multiple rifles,it would be too heavy for you!")
elif item == "rifle":
res = await use_this(ctx.author,item,amount)
if not res[0]:
if res[1]==1:
await ctx.reply(f"{ctx.author.mention} That Object isn't there!")
return
if res[1]==2:
await ctx.reply(f"{ctx.author.mention} You don't have {amount} {item} in your bag.")
return
if res[1]==3:
await ctx.reply(f"{ctx.author.mention} You don't have {item} in your bag.")
return
aninames = ['bear','rabbit','wolf']
animals = random.choice(aninames)
earnings = random.randrange(5000)
await ctx.reply(f"You used hunted {animals} for {earnings} coins!,you lost the rifle in the process tho ..")```
【问题讨论】:
-
能否请您发布完整的回溯?
标签: python discord discord.py