简体   繁体   中英

lvl system for discord python sql3

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.

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,)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM