如何使更新命令工作?上面脚本的其余部分可以工作,但更新失败


@commands.command()
@commands.cooldown(1, 8, commands.BucketType.user)
async def Beg(self, ctx):
possibility = randint(1, 10)
if possibility == 5:
await ctx.send("I'll just give you this <:DiscordError:879192336960196619>")
else:
amount = randint(25, 175)
outcomes = [f"If you're going to keep begging me I guess I'll give you ${amount}", f"How about you get a job for yourself? But I guess I'll give you ${amount}", f"I'll give you ${amount} but you owe me cuddles after this!", f"Let me see what's in my wallet.. Oh it's ${amount}! Take it!"]
outcomes1 = random.choice(outcomes)
await ctx.send(outcomes1)
db = sqlite3.connect("main.sqlite")
cursor = db.cursor()
result = cursor.fetchone()
sql = f"UPDATE main SET money = * WHERE member_id = {ctx.message.author.id}"
val = (result[1] + amount)
cursor.execute(sql, val)
db.commit()
await ctx.send("Sent!")
cursor.close()
db.close()

正如我所说,update命令不起作用。结果消息运行良好。它被发送了,没有任何更新。

作为最佳实践,我建议将所有ctx确认消息移动到函数的末尾。我更喜欢这种方式,因为它将有助于作为一种调试(如果之前的所有步骤都成功了,那么就会发送一条确认消息(。

我建议删除cursor.close(),因为该方法不适用于光标对象。打开和关闭数据库连接,而不是光标。

result[1]也应该是result[0]。在不知道数据库是如何设置的情况下,在尝试对其进行数学运算之前,确保result[0]是一个整数也是值得的

相关内容

  • 没有找到相关文章

最新更新