![](/img/trans.png)
[英]Trying to make a Economy bot with quick.db, but my command is not working
[英]Losing data from Quick.db in my Discord Bot
我在 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 來制作我的代碼。 謝謝。
如果您使用的是 heroku 或 repl.it 或其他類似的,他們傾向於每天擦除本地數據,您可以在您的情況下使用 mongodb 或 json 或切換您的主機
使用 Repl.it 數據庫進行持久化! https://docs.repl.it/tutorials/11-using-the-replit-database
你可以試試QuickMongo 。 mongodb
基本上是quick.db
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']
repli 會在一兩天后自動刪除 'quickdb' 文件 更好更快地使用 'quickmongo'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.