简体   繁体   中英

quick.db leveling system - database.updateValue is not a function

I'm trying to make a leveling system with a discord bot using quick.db. I've been working with this for a while and couldn't figure it out so I figured I'd go here. My current code is: (app.js)

    //Message Leveling
    database.updateValue(message.author.id + message.guild.id, 1).then(i => {


        let messages;
        if (i.value = 25) messages = 25; // Level 1
        else if (i.value == 50) messages = 50; // Level 2
        else if (i.value == 75) messages = 75; //Level 3

        if (!isNaN(messages)) { // If messages iss STILL empty, run this
            database.updateValue(`userLevel_${message.author.id + message.guild.id}`, 1).then(o => {
                message.channel.send(`You sent ${messages} messages, LEVEL UP HOME BOY! level ${o.value}`)
            })
        }
    })

(messages.js)

const db = require('quick.db');
var database = require('quick.db')

exports.run = (bot, message, args, func) => {

    database.fetchObject(message.author.id + message.guild.id).then(i => {
        database.fetchObject(`userLevel_${message.author.id + message.guild.id}`).then(o => {
            message.channel.send('Messages sent: `' + (i.value + 1) + '`\nLevel: `' + o.value +'`');

        })
    })

}

Now, the error I get happens in app.js but I figured the code from messages.js might be helpful. The error is:

[help]     database.updateValue(message.author.id + message.guild.id, 1).then(i => {
[help]              ^
[help]
[help] TypeError: database.updateValue is not a function

Being new to this I still don't quite understand what a TypeError is or how to fix it, despite looking it up on google (I know, I'm a real researcher). So I was hoping someone could give me a hand. I also couldn't find an example of this error, so I'm pretty lost.

As always, thanks for taking the time to read my question, if I got any terminology wrong feel free to ask me about what I mean, or you can just call me stupid. <3

database.updateValue isn't a function, instead you would want to use database.add like:

    database.add(`level_${message.guild.id}_${message.author.id}`, 1).then(i => {


    let messages;
    if (i.value = 25) messages = 25; // Level 1
    else if (i.value == 50) messages = 50; // Level 2
    else if (i.value == 75) messages = 75; //Level 3

    if (!isNaN(messages)) { // If messages iss STILL empty, run this
        database.add(`level_${message.guild.id}_${message.author.id}`, 1).then(o => {
            message.channel.send(`You sent ${messages} messages, LEVEL UP HOME BOY! level ${o.value}`)
        })
    }
})

For fetching databases, fetchObject isn't a function, use fetch or get

const db = require('quick.db');
var database = require('quick.db')

exports.run = (bot, message, args, func) => {

db.fetch(level_${message.guild.id}_${message.author.id}).then(i => {
    db.fetch(level_${message.guild.id}_${message.author.id}).then(o => {
        message.channel.send('Messages sent: `' + (i.value + 1) + '`\nLevel: `' + o.value +'`');

    })
})

}

If you've defined quick.db as db then instead of calling database , call db otherwise it just wouldn't work.

Thanks, Chills

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