【发布时间】:2020-06-16 13:29:34
【问题描述】:
所以我正在研究一个不和谐的货币系统。我用下面的代码给别人钱。
@client.command()
async def give_money(ctx, member: discord.Member, amount: int):
connection = sqlite3.connect("testdatabase.db")
cur = connection.cursor()
cur.execute(f"UPDATE currency_value_table SET currency = currency - {amount} WHERE
member_id = {ctx.author.id}")
record = cur.fetchone()[0]
if record < amount:
return await ctx.send("Bruh you too poor to do that!")
else:
await ctx.send(f"{amount} given to {member.display_name}")
cursor.execute(f"UPDATE currency_value_table SET currency = currency + {amount} WHERE member_id = {member.id}")
connection.commit()
connection.close()
database_record = cur.fetchone()[0]
money = database_record
await ctx.send(f"You are clearly a broke college student.. you have {money} dollars")
但是,当我运行它时,我会收到以下消息:
File "discord.bot.py", line 398, in give_money
record = cur.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable
我不确定这是一个无类型,因为如果我运行它:
@client.command()
async def bal(ctx):
connection = sqlite3.connect("testdatabase.db")
cur = connection.cursor()
cur.execute(f"SELECT currency FROM currency_value_table WHERE member_id = {ctx.author.id}")
record = cur.fetchone()[0]
connection.commit()
connection.close()
await ctx.send(f"You are clearly a broke college student.. you have {record} dollars")
cur.execute(f"SELECT currency FROM currency_value_table WHERE member_id = {ctx.author.id}")
工作正常吗?
【问题讨论】:
标签: python database sqlite discord discord.py