discord python sql3 的 lvl 系统

lvl system for discord python sql3

等级系统不起作用

    @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()

错误:

   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.

您需要为 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()

注意这里需要打个逗号:(user,)