错误:SQLITE_ERROR:在“ READD”附近:语法错误

时间:2019-09-06 10:50:53

标签: node.js discord.js node-sqlite3

从昨天开始,我一直使用旧代码,以前没有任何错误,更改过代码,并且使用新代码编写的,都是因为这个无法解决的问题,同样的错误。

试图修复旧代码 用更少的代码和只有一个cmd完成了相同任务的新代码。

/* eslint-disable no-undef */
/* eslint-disable no-empty */

const Discord = require('discord.js');
const Sqlite = require('sqlite3').verbose();

const client = new Discord.Client();

const db = new Sqlite.Database('C:/Users/buett/Documents/Source/Visual Studio Code/Violet Bot/database.db', Sqlite.OPEN_CREATE | Sqlite.OPEN_READWRITE, (err) => {
    if (err) {
        console.error(err.message);
    }
    console.log('Database connected!');
});

client.on('error', (err) => {
    console.error(err.message);
});

client.once('ready', () => {
    console.log(`In ${client.guilds} online!`);
});

client.on('message', async (msg) => {

    const prefix = "*";

    const args = msg.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    const id = args[0];
    const role = args[1];
    const emote = args[2]


    // const emoji = args[2];

    switch (command) {
        case 'add':
            // eslint-disable-next-line no-case-declarations

            if (!msg.author.bot || msg.member.hasPermission("MANAGE_ROLES_OR_PERMISSIONS")) {

                let cmd = "*add [ID] [ROLE] [EMOTE]"

                if (id > 0) {
                    if (msg.guild.roles.find(r => r.name == role, r => r.id == role) || msg.mentions.roles.first()) {

                        const emoteid = emote.replace('>', '').split(':', 3).slice(2);
                        const emotestring = emoteid[0].toString()
                        console.log(emoteid)

                        if (msg.guild.emojis.find(e => e.id == emoteid)) {

                            await db.run(`CREATE TABLE [IF NOT EXISTS] READD (id INTEGER PRIMARY KEY, role TEXT, emoteid TEXT)`, (error) => {
                                if (!error) {
                                    db.run(`INSERT INTO READD (id, role, emoteid) VALUES (?, ?, ?)`, [id, role, emotestring])

                                }
                                return console.error(error)
                            });

                        } 
                        else {
                            let errorcmd = "EMOTE is not existing or incorrect!"
                            missingArgsMessage(msg, command, cmd, errorcmd)
                        }
                    }
                    else {
                        let errorcmd = "ROLE is not existing or incorrect!";
                        return missingArgsMessage(msg, command, cmd, errorcmd);
                    }
                }
                else {
                    let errorcmd = "ID muss eine Zahl sein!";
                    missingArgsMessage(msg, command, cmd, errorcmd);
                }
            }
            else {
                let perms = "MANAGE_ROLES_OR_PERMISSIONS";
                return permsMessage(msg, perms);
            }
            break;
    }
}).login('NDk1MjAzNDMyNzczMTg5NjMy.XUwBdQ.0HdHDSTc_SWsueymgZhLwO7Y3iQ');

function missingArgsMessage(msg, command, cmd, errorcmd) {
    msg.channel.send({
        embed: {
            color: 0xf44336,
            title: `**CMD Error:** _${command}_`,
            description: `${errorcmd}`,
            footer: {
                icon_url: 'http://icons.iconarchive.com/icons/froyoshark/enkel/256/iTerm-icon.png',
                text: 'CMD Usage >> ' + cmd
            }
        }

    });
}

function permsMessage(msg, perms) {
    msg.channel.send({
        embed: {
            color: 0xd50000,
            title: `**PERMS ERROR:** "${perms}"`,
            description: `You need more permission to do that!`
        }

    });
}

我希望代码将创建一个具有id,role和emote参数的数据库 但是输出是这样的:

[Error: SQLITE_ERROR: near "READD": syntax error] {
  errno: 1,
  code: 'SQLITE_ERROR'
}

1 个答案:

答案 0 :(得分:0)

您需要在查询中删除多余的[],它们在此处表示这是可选的,因此查询变为

await db.run(`CREATE TABLE IF NOT EXISTS READD (id INTEGER PRIMARY KEY, role TEXT, emoteid TEXT)...`