简体   繁体   English

在我的 Discord Bot 中丢失来自 Quick.db 的数据

[英]Losing data from Quick.db in my Discord Bot

I have a bot game in Discord, so i've used 'express' library to set the bot online (I guess).我在 Discord 中有一个机器人游戏,所以我使用“express”库将机器人设置为在线(我猜)。 First of all to be clear, I'm not a dev pro, only a person who learned watching tutorials in YT.首先要明确一点,我不是开发专家,只是一个在 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一个简单的命令代码示例,我用 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. PS:如果这很重要,我已经使用 Repl.it 来制作我的代码。 Thanks.谢谢。

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如果您使用的是 heroku 或 repl.it 或其他类似的,他们倾向于每天擦除本地数据,您可以在您的情况下使用 mongodb 或 json 或切换您的主机

Use Repl.it Database for persistence!使用 Repl.it 数据库进行持久化! https://docs.repl.it/tutorials/11-using-the-replit-database https://docs.repl.it/tutorials/11-using-the-replit-database

you can try QuickMongo .你可以试试QuickMongo It is basically quick.db for mongodb mongodb基本上是quick.db

Test测试

QuickMongo 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']

replit automatically deletes 'quickdb' files after a day or two use 'quickmongo' better and faster repli 会在一两天后自动删除 'quickdb' 文件 更好更快地使用 'quickmongo'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM