[英]quick.db leveling system - database.updateValue is not a function
I'm trying to make a leveling system with a discord bot using quick.db.我正在尝试使用 quick.db 使用 discord 机器人制作一个调平系统。 I've been working with this for a while and couldn't figure it out so I figured I'd go here.
我已经研究了一段时间,但无法弄清楚,所以我想我会在这里 go 。 My current code is: (app.js)
我当前的代码是:(app.js)
//Message Leveling
database.updateValue(message.author.id + message.guild.id, 1).then(i => {
let messages;
if (i.value = 25) messages = 25; // Level 1
else if (i.value == 50) messages = 50; // Level 2
else if (i.value == 75) messages = 75; //Level 3
if (!isNaN(messages)) { // If messages iss STILL empty, run this
database.updateValue(`userLevel_${message.author.id + message.guild.id}`, 1).then(o => {
message.channel.send(`You sent ${messages} messages, LEVEL UP HOME BOY! level ${o.value}`)
})
}
})
(messages.js) (消息.js)
const db = require('quick.db');
var database = require('quick.db')
exports.run = (bot, message, args, func) => {
database.fetchObject(message.author.id + message.guild.id).then(i => {
database.fetchObject(`userLevel_${message.author.id + message.guild.id}`).then(o => {
message.channel.send('Messages sent: `' + (i.value + 1) + '`\nLevel: `' + o.value +'`');
})
})
}
Now, the error I get happens in app.js but I figured the code from messages.js might be helpful.现在,我得到的错误发生在 app.js 中,但我认为messages.js 中的代码可能会有所帮助。 The error is:
错误是:
[help] database.updateValue(message.author.id + message.guild.id, 1).then(i => {
[help] ^
[help]
[help] TypeError: database.updateValue is not a function
Being new to this I still don't quite understand what a TypeError is or how to fix it, despite looking it up on google (I know, I'm a real researcher).作为新手,我仍然不太了解 TypeError 是什么或如何修复它,尽管在谷歌上查找它(我知道,我是一个真正的研究人员)。 So I was hoping someone could give me a hand.
所以我希望有人能帮我一把。 I also couldn't find an example of this error, so I'm pretty lost.
我也找不到这个错误的例子,所以我很迷茫。
As always, thanks for taking the time to read my question, if I got any terminology wrong feel free to ask me about what I mean, or you can just call me stupid.一如既往,感谢您花时间阅读我的问题,如果我有任何术语错误,请随时问我我的意思,或者您可以称我为愚蠢。 <3
<3
database.updateValue
isn't a function, instead you would want to use database.add
like: database.updateValue
不是 function,而是您希望使用database.add
,例如:
database.add(`level_${message.guild.id}_${message.author.id}`, 1).then(i => {
let messages;
if (i.value = 25) messages = 25; // Level 1
else if (i.value == 50) messages = 50; // Level 2
else if (i.value == 75) messages = 75; //Level 3
if (!isNaN(messages)) { // If messages iss STILL empty, run this
database.add(`level_${message.guild.id}_${message.author.id}`, 1).then(o => {
message.channel.send(`You sent ${messages} messages, LEVEL UP HOME BOY! level ${o.value}`)
})
}
})
For fetching databases, fetchObject
isn't a function, use fetch
or get
对于获取数据库,
fetchObject
不是 function,使用fetch
或get
const db = require('quick.db');
var database = require('quick.db')
exports.run = (bot, message, args, func) => {
db.fetch(level_${message.guild.id}_${message.author.id}).then(i => {
db.fetch(level_${message.guild.id}_${message.author.id}).then(o => {
message.channel.send('Messages sent: `' + (i.value + 1) + '`\nLevel: `' + o.value +'`');
})
})
}
If you've defined quick.db
as db
then instead of calling database
, call db
otherwise it just wouldn't work.如果您已将
quick.db
定义为db
,则不要调用database
,而是调用db
,否则它将无法正常工作。
Thanks, Chills谢谢,寒战
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.