我正在制作一個不和諧的機器人并為其增加經濟性。我已經使用 SQLite 制作了一個錢包和余額系統。我想發出一個發送命令,但是當我執行 .send 時,它給了我一個錯誤:
if amount / 100 * 1 amount > Result_userBal:
TypeError: unsupported operand type(s) for /: 'str' and 'int'
我的代碼是:
@client.command(aliases=["pay", "s", "send" ])
async def Send(ctx, member: discord.Member, amount=None):
db.commit()
cursor = db.cursor()
USERID = ctx.message.author.id
USER_NAME = str(ctx.message.author)
START_BAL = 0
amt = amount
TARGETID = discord.member
cursor.execute (f"SELECT WalletID from Wallets WHERE WalletID={USERID}")
result_userID = cursor.fetchone()
cursor.execute(f"SELECT WalletBal from Wallets WHERE WalletID={USERID}")
Result_userBal = cursor.fetchone()
注意:我沒有放在這里,但是這里我有一個系統可以檢查帳戶是否有錢包,以及金額是否足夠。
else:
cursor.execute(f"SELECT WalletID from Wallets WHERE WalletID= {USERID}")
cursor.execute(f"UPDATE Wallets SET WalletBal = WalletBal - {amt}")
cursor.execute(f"UPDATE Wallets SET WalletBal = WalletBal - {amt/100}")
db.commit()
cursor.execute(f"SELECT WalletID from Wallets WHERE WalletID= {TARGETID}")
cursor.execute(f"UPDATE Wallets SET WalletBal = WalletBal {amt}")
db.commit()
await ctx.send ("The Transaction was succesfull!")
我將扣除 101% 的交易金額作為傭金。
uj5u.com熱心網友回復:
感覺您提供的大多數代碼與問題無關 - 所有錯誤意味著變數“數量”當前是一個字串,因此不能除以 100(整數)。試著把線
amount = int(amount)
就在您的 if 陳述句之前,看看是否有幫助。(我會將此放在評論中,但我還沒有聲譽)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/498260.html
上一篇:游標應該只選擇具有不同值的單元格
