-1

我在 Discord 中有一个机器人游戏,所以我使用“express”库将机器人设置为在线(我猜)。首先要明确一点,我不是开发专家,只是一个在 YT 看教程学习的人。所以我创建了一个机器人游戏,但有时,我的机器人突然下线,我的游戏中的用户在游戏中丢失了物品、现金和类似的东西。我注意到这就像数据库失去了时间并从几分钟前回到数据库。有人知道可以这样做吗?我该如何解决?

一个简单的命令代码示例,我用 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:如果这很重要,我已经使用 Repl.it 来制作我的代码。谢谢。

4

4 回答 4

0

repli 会在一两天后自动删除 'quickdb' 文件 更好更快地使用 'quickmongo'

于 2021-04-03T03:03:08.400 回答
0

如果您使用 heroku 或 repl.it 或其他类似的工具,他们倾向于每天擦除本地数据,您可以在您的情况下使用 mongodb 或 json 或切换您的主机

于 2021-01-10T15:30:38.927 回答
0

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

于 2021-01-13T02:17:12.150 回答
0

你可以试试QuickMongo。基本上是quick.db为了mongodb

测试

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']
})

快速数据库

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']
于 2021-01-13T05:47:51.510 回答