# cogs/money.py
@commands.command()
async def beg(self, ctx):
pass
await open_account(ctx.author)
users = await get_bank_data()
user = ctx.author
earnings = random.randrange(101)
await ctx.send(f"某人給了你 {earnings} 塊錢!!")
users[str(user.id)]["wallet"] += earnings
with open("bank.json", "w") as f:
json.dump(users, f)
async def update_bank(user, change = 0, mode = "wallet"):
pass
users = await get_bank_data()
users[str(user.id)][mode] += change
with open("bank.json", "w") as f:
json.dump(users, f)
money = [users[str(user.id)]["wallet"], users[str(user.id)]["bank"]]
return money
import asyncio
@commands.command()
async def slots(self, ctx, amount = None, mang = None):
pass
await open_account(ctx.author)
if mang == None:
await ctx.send("請輸入倍率")
return
bal = await update_bank(ctx.author)
amount = int(amount)
mang = int(mang)
if bal[0] <= 0:
await ctx.send("沒錢的,滾拉")
return
if amount > bal[0]:
await ctx.send("你沒這麼多錢拉幹")
return
if amount < 0:
await ctx.send("正整數...")
return
# 做出限制
if amount > 200 or mang > 10 :
await ctx.send("不接受太高金額及倍率,最高為199$$")
return
final = []
for i in range(3):
a = random.choice(["X", "O", "Q"])
final.append(a)
ans = mang * amount
pos = mang * amount * -1
# win
if final[0] == final[1] == final[2]:
await update_bank(ctx.author, ans)
await ctx.send("想贏嗎??")
asyncio.sleep(3)
await ctx.send(str(final))
await ctx.send(f"你贏了 {ans} 塊錢")
# lose
else:
await update_bank(ctx.author, pos)
await ctx.send("想贏嗎??")
asyncio.sleep(3)
await ctx.send(str(final))
await ctx.send(f"你輸了 {pos} 塊錢")
第一,關於次數,其實當初是有想過限制次數的,但後來想想好像沒必要
第二,關於倍率,這部分可以自己做更改,畢竟是random
第三,搶銀行.......好像挺不道德的
畢竟所謂的亂數並不是真的隨機,有興趣的話可以點這裡看看別人的說法