Home > Enterprise >  lvl system for discord python sql3
lvl system for discord python sql3

Time:03-19

The level system does not work

    @bot.event
    async def on_message(message):
        user = message.author.id
        conn = sqlite3.connect('server.db')
        cur = conn.cursor()
        cur.execute('SELECT xp, lvl FROM users WHERE id = ?')
        results = cur.fetchone()
        row = results[0]
        old_xp = row[0]
        old_level = row[1]
        new_xp = old_xp   1
        if new_xp == 2:
            new_level = 1
        else:
            new_level = old_level
    
        cur.execute('UPDATE users SET xp = ?, level = ? WHERE id = ?', (new_xp, new_level, user)
                    )
        conn.commit()
        conn.close()

Error:

   cur.execute('SELECT xp, lvl FROM users WHERE id = ?')
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.

CodePudding user response:

You need to pass a value for the id.

@bot.event
async def on_message(message):
    user = message.author.id
    conn = sqlite3.connect('server.db')
    cur = conn.cursor()
    cur.execute('SELECT xp, lvl FROM users WHERE id = ?', (user,))
    results = cur.fetchone()

Note that you need to put a comma here: (user,)

  • Related