Discord bot with quick.db, db.startsWith is not a function


#1

so i’ve just moved my bot to glitch, and all commands works fine, except of this one:

const db = require('quick.db')
const ms = require('parse-ms')
const Discord = require('discord.js')

exports.run = async (client, message, args, config) => {

    let user = message.author;

if (args == 'coins') {
const resp = await db.startsWith('Balance', { sort: '.data'});
resp.length = 10;
let finalOutput = ' ';
for (var i in resp) {
    finalOutput += `**${client.users.get(resp[i].ID.split("_")[1]).tag}** ~-~ ${resp[i].data} :coins: \n`;

}
message.channel.send({"embed":{
    title: "**TOP**",
    color: 0xf10f3c,
    fields:[{
        name: "Sorted by coins",
        value: finalOutput,
        inline:true
    }]}})
}}

it says that db.startsWith is not a function, but if i host it from my pc, it works fine… what am i doing wrong? i’ve already checked node and dependencies versions and they’re all the same (quick.db is ^7.0.0-b21)
just in case:

    "express": "^4.16.4",
    "discord.js": "^11.4.2",
    "moment": "^2.24.0",
    "parse-ms": "^2.0.0",
    "quick.db": "^7.0.0-b21"
  }

#2

Hi @koliron, welcome to the Glitch forum!

It looks to me like you might actually be getting quick.db version 7.0.0-b22 instead of 7.0.0-b21 - when I spin up a new project with that package.json dependency that’s what I get, which is consistent with the semantics of “^” in package versions (it’s a little arcane to me, and you can read more about it at https://docs.npmjs.com/misc/semver, but as I read it “^” in this case means “allow any version that’s in the 7.x family”).

When I do a console.log(db) after requireing that package, I get a version of 7.0.0b22 and indeed it seems like that version doesn’t export a startsWith function, while 7.0.0b21 does. If you remove the “^” from the beginning of the quick.db version specifier I think your current code will work, but it seems as though that function is being deprecated and I’d probably find a different solution to that instead.


#3

you’re right, now it works! thank you!!
and yes, im gonna try to find another way to write this command