简体   繁体   中英

Error While Saving Data “Cannot read property 'get' of undefined”

IM trying to set up bettersqlite3 to save data. I'm following an idiots guide, but it gives me error no matter how I implement it into my code. The error I'm talking about is "TypeError: Cannot read property 'get' of undefined." Here's my code:

if (message.content.startsWith(`${prefix}bclear`)) {
    message.delete()

    score = client.getScore.get(message.author.id);

    if (!score) {
        score = {
            id: `${message.author.id}`,
            points: 0
        };
    }
    score.points++;
}

Thanks for your help!

Why haven't you used

client.getScore = sql.prepare(`SELECT * FROM scores WHERE id = ${message.author.id}`);

the reason you would use the? is to protect against SQL injection, but that isn't needed because the user cannot remotely input data.

The first thing you do within your conditional statement is "message.delete()". Without seeing the data structure of 'message' I would guess that this deletes the message object itself causing any references to 'message.xx' to fail.

I'm guessing that you are trying to delete only a portion of the message object but perhaps you are deleting the entire object.

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