-1

I have a bot game in Discord, so i've used 'express' library to set the bot online (I guess). First of all to be clear, I'm not a dev pro, only a person who learned watching tutorials in YT. So I've created a bot game, but sometimes, my bot get offline suddenly and the users from my game lost Items, Cash and stuff like that in the game. I noticed that is like the database lost time and get back to the database from minutes ago. Someone know what could be doing that? And how I can fix?

An simple exemple of command code I've use to make my database with quick.db

let money = await db.fetch(`money_${user.id}`)
let amount = 300

if(message.content === (`${PREFIX}daily`)) {
  db.add(`money_${user.id}`, amount)
  message.channel.send(`${username} received your daily reward ${amount} money!`)
}

PS: I've use Repl.it to make my codes, if that matters. Thanks.

alienjs
  • 1
  • 1
  • Yeah the problem is you're hosting on repl.it - when it times out it probably clears the database - if you want to keep using repl.it to host the bot you'll have to look for another platform to host the database on such as [Firestore](https://firebase.google.com/docs/firestore/) or move the bot to another host – Pentium1080Ti Jan 10 '21 at 09:34

4 Answers4

1

you can try QuickMongo. It is basically quick.db for mongodb

Test

QuickMongo

const { Database } = require("quickmongo");
const db = new Database("mongodb://localhost/quickmongo");

db.once("ready", () => {
    // Setting an object in the database:
    db.set("userInfo", { difficulty: "Easy" }).then(console.log);
    // -> { difficulty: 'Easy' }

    db.push("userInfo.items", "Sword").then(console.log);
    // -> { difficulty: 'Easy', items: ['Sword'] }

    db.add("userInfo.balance", 500).then(console.log);
    // -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }

    // Repeating previous examples:
    db.push("userInfo.items", "Watch").then(console.log);
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }

    db.add("userInfo.balance", 500).then(console.log);
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }

    // Fetching individual properties
    db.get("userInfo.balance").then(console.log);
    // -> 1000
    db.get("userInfo.items").then(console.log);
    // -> ['Sword', 'Watch']
})

QuickDB

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

// Setting an object in the database:
db.set('userInfo', { difficulty: 'Easy' })
// -> { difficulty: 'Easy' }

// Pushing an element to an array (that doesn't exist yet) in an object:
db.push('userInfo.items', 'Sword')
// -> { difficulty: 'Easy', items: ['Sword'] }

// Adding to a number (that doesn't exist yet) in an object:
db.add('userInfo.balance', 500)
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }

// Repeating previous examples:
db.push('userInfo.items', 'Watch')
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
db.add('userInfo.balance', 500)
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }

// Fetching individual properties
db.get('userInfo.balance') // -> 1000
db.get('userInfo.items') // ['Sword', 'Watch']
Andromeda
  • 340
  • 4
  • 9
0

If you are using heroku or repl.it or others like it they tend to wipe local data daily you can use mongodb or json's in your case or switch your host

Arnav Mishra
  • 488
  • 2
  • 15
0

Use Repl.it Database for persistence! https://docs.repl.it/tutorials/11-using-the-replit-database

Amjad Masad
  • 4,035
  • 1
  • 21
  • 20
0

replit automatically deletes 'quickdb' files after a day or two use 'quickmongo' better and faster

Pluto
  • 29
  • 6