Search code examples
node.jsdiscorddiscord.js

Problem when launching the bot due to quick.db


I have a problem with my bot discord I updated everything better sqlite quick DB but when I launch the bot always the same error someone could help me?

PS C:\Users\berno\Desktop\Bot-Parfait-main> node index.js
C:\Users\berno\Desktop\Bot-Parfait-main\index.js:7
const table = new db.table('Prefix');
              ^

TypeError: db.table is not a constructor
    at Object.<anonymous> (C:\Users\berno\Desktop\Bot-Parfait-main\index.js:7:15)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.11.0
PS C:\Users\berno\Desktop\Bot-Parfait-main> 

And there was my code :

const { Client, Intents, guild, Collection } = require('discord.js');
const Discord = require("discord.js")
const config = require('./config')
const { readdirSync } = require("fs")
const { QuickDB } = require("quick.db");
const db = new QuickDB();
const table = new db.table('Prefix');
const logembed = new db.table("embedlog")
ms = require("ms")
const color = config.app.color
const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_BANS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, Intents.FLAGS.GUILD_INTEGRATIONS, Intents.FLAGS.GUILD_WEBHOOKS, Intents.FLAGS.GUILD_INVITES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MESSAGE_TYPING, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGE_TYPING],
    restTimeOffset: 0,
    partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION"]
});

client.login(config.app.token);
client.commands = new Collection();

const { GiveawaysManager } = require('discord-giveaways');
client.giveawaysManager = new GiveawaysManager(client, {
    storage: "./database.json",
    updateCountdownEvery: 3000,
    default: {
        botsCanWin: false,
        embedColor: "#FF0000",
        reaction: "🎉"
    }
});

Thanks Advance !

I installed the last update and updated the code. I did everything I could.


Solution

  • The error is quite clear, you can't construct a new instance from db.table now on QuickDB. You can go ahead and access db.table('Prefix') without the new keyword. This is because the table function on QuickDB doesn't need the new keyword again. You can read more on the migration guide here

    Update your code to access db.table directly like below and everything should work properly.

    const table = db.table('Prefix');
    const logembed = db.table("embedlog")
    

    Let me know if this helps.