所以我正在创建一个赌博机器人,我创建了一个插槽命令。这个命令之前是工作的,但由于某种原因停止了,下面是代码:
@client.command()
async def slots(ctx, amount=None):
if amount == None:
return await ctx.send("Please enter an amount you would like to bet!")
await open_account(ctx.author)
bal = await update_bank(ctx.author)
amount = int(amount)
if amount <50:
return await ctx.send("You must bet at least $50")
else:
if amount>bal[0]:
return await ctx.send("You don't have that much money")
if amount <0:
return await ctx.send("Amount must be larger than 0")
final = []
for i in range(3):
a = random.choice(["🥞", "🍖", "🌀", "💧", "🎈", "🎄", "🎱", "🧠", "🐥"])
final.append(a)
slotsEmbed = discord.Embed(title=f"{ctx.author.name}'s slots game")
slotsEmbed.add_field(name="Your slots game", value=str(final))
await ctx.send(embed=slotsEmbed)
if final[0] == final[1] == final[2]:
await update_bank(ctx.author, 3*amount)
await ctx.send("You won all 3 slots!")
elif final[0] == final[1] or final[0] == final[2] or final[1] == final[2]:
await update_bank(ctx.author, 2*amount)
await ctx.send("You won 2 slots!")
else:
await update_bank(ctx.author, -1*amount)
await ctx.send("You didn't win any slots.")
if amount>bal[0]:
行出现错误这对我来说很奇怪,因为就像我说的,这个命令曾经使用相同的代码,但是由于某种原因它停止了。
update_bank函数:
async def update_bank(user,change = 0,mode = "Wallet"):
users = await get_bank_data()
users[str(user.id)][mode] += change
with open("mainbank.json", "w") as f:
json.dump(users, f, indent=4)
bal = [users[str(user.id)]["Wallet"],users[str(user.id)]["Bank"]]
return user
我修复了它,在更新银行函数中,无论出于何种原因,我都有返回用户,这没有意义,因为我想改变用户的余额。我把它从"返回用户"改成了"返回用户"。要"返回bal_;"这就解决了我的问题!