【问题标题】:(Discord) SQLite 2 values 1 column error(不和谐)SQLite 2 值 1 列错误
【发布时间】:2018-12-18 04:00:31
【问题描述】:

我是一个不和谐的机器人开发人员并切换到 SQLite 我之前遇到了一些错误和问题,但已经解决了。创建多个表后,我收到一个错误,我似乎无法弄清楚这是错误:

(node:17024) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: SQLITE_ERROR: 2 values for 1 columns
(node:17024) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate
the Node.js process with a non-zero exit code.

我查看了所有表、列、值,但似乎没有任何问题这是我的代码:

client.sql.get(`SELECT * FROM settings WHERE guildid = "${message.guild.id}"`).then(row => {
        if(!row) {
            client.sql.run(`INSERT INTO settings (guildid, prefix, lang, color, admin, mod, user, autor, channel) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [message.guild.id, '!', 'en', '#ffffff', 'admin', 'mod', 'false', 'false', 'false'])
            client.gprefix = '!';
        } else {
            client.gprefix = row.prefix;
        }
    }).catch(() => {
        client.sql.run(`CREATE TABLE IF NOT EXISTS settings (guildid text NOT NULL, prefix text NOT NULL, lang text NOT NULL, color text NOT NULL, admin text NOT NULL, mod text NOT NULL, user text NOT NULL, autor text NOT NULL, channel text NOT NULL)`)
        client.sql.run(`INSERT INTO settings (guildid, prefix, lang, color, admin, mod, user, autor, channel) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [message.guild.id, '!', 'en', '#ffffff', 'admin', 'mod', 'false', 'false', 'false'])
            client.gprefix = '!';
    })
    // FARM
    client.sql.get(`SELECT * FROM farm WHERE userid = "${message.author.id}"`).then(row => {
        if(!row) {
            client.sql.run(`INSERT INTO farm (userid, money, xp, level, chickens, farmers, delivery, wizard, omega, robot, goldchick, cegg, ucegg, regg, eegg, legg, megg, elite, daily, collected, car, house, farm) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [message.author.id, 200, 0, 1, 0, 0, 0, '❓', '❓', '❓', '❓', 0, 1, 0, 0, 0, 0, 'false', 0, message.createdTimestamp, 10, 10, 10])
        }
    }).catch(() => {
        client.sql.run(`CREATE TABLE IF NOT EXISTS farm (userid text NOT NULL, money integer NOT NULL, xp integer NOT NULL, level integer NOT NULL, chickens integer NOT NULL, farmers integer NOT NULL, delivery integer NOT NULL, wizard text NOT NULL, omega text NOT NULL, robot text NOT NULL, goldchick text NOT NULL, cegg integer NOT NULL, ucegg integer NOT NULL, regg integer NOT NULL, eegg integer NOT NULL, legg integer NOT NULL, megg integer NOT NULL, elite text NOT NULL, daily integer NOT NULL, collected text NOT NULL, car integer NOT NULL, house integer NOT NULL, farm integer NOT NULL)`)
        client.sql.run(`INSERT INTO farm (userid, money, xp, level, chickens, farmers, delivery, wizard, omega, robot, goldchick, cegg, ucegg, regg, eegg, legg, megg, elite, daily, collected, car, house, farm) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [message.author.id, 200, 0, 1, 0, 0, 0, '❓', '❓', '❓', '❓', 0, 1, 0, 0, 0, 0, 'false', 0, message.createdTimestamp, 10, 10, 10])
    })
    // USERS
    client.sql.get(`SELECT * FROM users WHERE userid = "${message.author.id}"`).then(row => {
        if(!row) {
            client.sql.run(`INSERT INTO users (blacklisted, reason) VALUES (?, ?)`, ['false', 'None'])
            client.blacklisted = 'false'
            client.blackreason = 'None'
        } else {
            client.blacklisted = row.blacklisted
            if(client.blacklisted === 'true') {
            client.blackreason = row.reason;
            return message.channel.send(`You are blacklisted from the bot due to \`${client.blackreason}\`\n\n*Being blacklisted means that you can not use the bot*`).then(m => {
                msg.delete(10000)
            })
            }
        }
    }).catch(() => {
        client.sql.run(`CREATE TABLE IF NOT EXISTS users (blacklisted, reason)`)
        client.sql.run(`INSERT INTO users (blacklisted) VALUES (?, ?)`, ['false', 'None'])
    })

Rewire 解决了这个问题,谢谢!

【问题讨论】:

  • 您正在向 1 列 (blacklisted) VALUES (?, ?) 插入 2 个值,这可能是我不太确定是否可以显示特定行的问题,那会很有帮助。编辑:根据表创建查询它应该是(blacklisted, reason) VALUES (?, ?)
  • 谢谢你,我怎么没看到!
  • @ChickenDev 你能在答案中写下解决方案并接受它,这样你的问题看起来就不会没有答案吗?

标签: javascript database sqlite discord discord.js


【解决方案1】:

我用过:

(blacklisted) VALUES (?, ?)

而不是

(blacklisted, reason) VALUES (?, ?)

这使它成为 1 列的 2 个值,我在这里用上面的这个修复了它 ^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 2022-08-04
    • 2017-10-03
    相关资源
    最近更新 更多