如何修复意外的令牌错误?

时间:2017-11-11 06:25:33

标签: javascript sql

const prefix = "s!";
var dailyCheck = sql.get(`SELECT daily FROM scores WHERE userId = "${msg.author.id}"`);


bot.on("message", function (msg) {
    if (msg.author.bot) return;
    if (msg.content.toLowerCase = prefix + "dailies") {
        var daily = dailies(msg);
        daily; }
    });
bot.on("message", function dailies(msg) {
    reset.setInterval(function () {
        var date = new Date();
        if (date.getHours() === 15 && date.getMinutes() === 0) {
            sql.run(`UPDATE scores SET daily = 0`);
        }
    }, 60000);
    sql.run("CREATE TABLE IF NOT EXISTS scores (userId TEXT, daily INTEGER, glimmer INTEGER, wr INTEGER, rotw INTEGER)").then() => { 
        if (!row) {
            // I get the error of unexpected token "." in the next line.
            sql.run("CREATE TABLE IF NOT EXISTS scores (userId TEXT, points INTEGER, level INTEGER)").then() => {
            sql.run("INSERT INTO scores (userId, daily, points, wr, rotw) VALUES (?, ?, ?, ?, ?)", [msg.author.id, 1, 200, 0, 0]);
            msg.channel.send('Thank you for joining Playing Destiny Fast! You have 200 glimmer available!');
        } else if (dailyCheck = 1) {
            msg.channel.send('You have already accepted your daily rewards! Come back after the daily reset (9am PST) to claim again.');
        } else {
            sql.run(`UPDATE scores SET glimmer = ${row.glimmer + 200}, daily = 1, WHERE userId = ${msg.author.id}`);
            msg.channel.send('${message.author.id} has claimed their 200 daily glimmer! Total: ${row.glimmer}');
        }
    });
});

具体来说,我收到了一个"意外的令牌。"错误sql.run(CREATE...请告诉我如何解决此问题。

1 个答案:

答案 0 :(得分:1)

您错误地使用.then其中一个sql.run。 您正在执行的.then() => {无效,因为您正试图在不能的地方创建箭头功能。
相反,它应该是.then(() => {,因为它为.then方法提供了箭头函数,并消除了意外的令牌错误。

修正版(用reset.setInterval替换后的块)。

sql.run("CREATE TABLE IF NOT EXISTS scores (userId TEXT, daily INTEGER, glimmer INTEGER, wr INTEGER, rotw INTEGER)").then(() => { 
    if (!row) {
        // I get the error of unexpected token "." in the next line.
        sql.run("CREATE TABLE IF NOT EXISTS scores (userId TEXT, points INTEGER, level INTEGER)").then(() => { // this is where the issue was occurring
            sql.run("INSERT INTO scores (userId, daily, points, wr, rotw) VALUES (?, ?, ?, ?, ?)", [msg.author.id, 1, 200, 0, 0]);
            msg.channel.send('Thank you for joining Playing Destiny Fast! You have 200 glimmer available!');
        });
    } else if (dailyCheck = 1) {
        msg.channel.send('You have already accepted your daily rewards! Come back after the daily reset (9am PST) to claim again.');
    } else {
        sql.run(`UPDATE scores SET glimmer = ${row.glimmer + 200}, daily = 1, WHERE userId = ${msg.author.id}`);
        msg.channel.send('${message.author.id} has claimed their 200 daily glimmer! Total: ${row.glimmer}');
    }
});

我建议使用像VSCode这样的IDE或其他任何东西,它会(通常)显示错误,有时甚至会帮助您修复它们。