I have a aiosqlite Python database for a discord bot using Nextcord. I have one table that works fine but the second one just wont update or maybe even create (I'm not sure). I'm wondering if it being in a class for a Nextcord cog is something to do with the issue.
I tried almost everything I could think of even using chatGPT. I Have no idea why its like this and don't use SQL DS's enough to know why. I have been trying to fix this for over 3 months so any help would be appreciated.
The code is here:
async def create_tables(self):
if self.db is not None:
await self.db.execute('CREATE TABLE IF NOT EXISTS econ (spin_tokens INTEGER, tokens INTEGER, slash_cmds INTEGER, status INTEGER, dank INTEGER, user INTEGER)')
await self.db.execute('CREATE TABLE IF NOT EXISTS daily (daily_claim INTEGER, daily_claimed_stamp INTEGER, daily_streak INTEGER, user INTEGER)')
async def commit(self):
await self.connect.commit()
@commands.Cog.listener()
async def on_ready(self):
self.bot.db = await aiosqlite.connect("econ.db")
await asyncio.sleep(3)
await self.create_tables()
await self.bot.db.commit()
print("DB ready...")
print("-----------")`
async def get_dval(self, user):
async with self.bot.db.cursor() as cursor:
await cursor.execute("SELECT daily_claim, daily_claimed_stamp, daily_streak FROM daily WHERE user = ?", (user.id,))
data = await cursor.fetchone()
print(data)
if data is None:
await self.daily_make(user)
return 0, 0, 1, 0
(daily_claim, daily_claimed_stamp, daily_streak) = data[0], data[1], data[2]
return daily_claim, daily_claimed_stamp, daily_streak
async def dclaimed_update(self, user, mode="daily_claim"):
now = datetime.now()
now_time = now.strftime("%H.%M")
print(now_time)
if self.db is not None:
await self.db.execute(f'''UPDATE daily SET daily_claim = now_time WHERE user = (user.id)''')
await self.db.commit()
@nextcord.slash_command(description="adds to bal")
async def daily(self, interaction : Interaction):
now = datetime.now()
now_time = now.strftime("%H.%M")
print(now_time)
daily_claim, daily_claimed_stamp, daily_streak = await self.get_dval(interaction.user)
if daily_claim == 0:
resK = await self.dclaimed_update(interaction.user)
daily_claim, daily_claimed_stamp, daily_streak = await self.get_dval(interaction.user)
await interaction.send("Sugg")
else:
await interaction.send("No")