'SQLite NULL with discord.py
I have problem with my SQLITE. My lvlexp and messages are NULL
I want that messages = 0 and lvlexp = 100
with this Code I have NULL
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
author = message.author
guild = message.guild
async with aiosqlite.connect('level.db') as db:
async with db.cursor() as cursor:
await cursor.execute("SELECT xp FROM levels WHERE user = ? AND guild = ?", (author.id,guild.id,))
xp = await cursor.fetchone()
await cursor.execute("SELECT level FROM levels WHERE user = ? AND guild = ?", (author.id,guild.id,))
level = await cursor.fetchone()
if not xp or not level:
await cursor.execute("INSERT INTO levels (level,xp,user,guild) VALUES (?, ?, ?, ?)", (0, 0, author.id,guild.id,))
await db.commit()
await cursor.execute("SELECT lvlexp FROM levels WHERE user = ? AND guild = ?", (author.id,guild.id,))
lvlexp = await cursor.fetchone()
await cursor.execute("SELECT messages FROM levels WHERE user = ? AND guild = ?", (author.id,guild.id,))
messages = await cursor.fetchone()
if not lvlexp:
await cursor.execute("INSERT INTO levels (lvlexp,messages) VALUES (?, ?)", (100,0,))
await db.commit()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
