简体   繁体   English

Lowdb 返回未定义

[英]Lowdb return undefined

I'm doing a Discord bot with command handling, but on a file, I can't get the content of my JSON file out with lowdb... I proceed exactly the same way with success in the other files, I don't understand... Here is my code:我正在做一个带有命令处理的 Discord 机器人,但是在一个文件上,我无法使用 lowdb 获取我的 JSON 文件的内容......我在其他文件中以完全相同的方式成功,我没有明白……这是我的代码:

const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('../db.json')
const db = low(adapter)
const adapter2 = new FileSync('../users.json')
const users = low(adapter2)
const fetch = require('node-fetch');
const config = require('../config.json');
const api = config.api;

module.exports = {
    name: 'rent',
    description: 'Rent a number',
    usage: '<country>',
    guildOnly: true,

  async execute(message, args) {
    return console.log(db.get().value())

...

Here's my db.json:这是我的 db.json:

{
  "numbers": [
    {
      "test": "1234"
    }
  ]
}

When I console.log db alone, it takes me out the object, but as soon as I try to console.log with lowdb like above it takes me out undefined ....当我单独使用 console.log db 时,它会将我取出对象,但是一旦我尝试使用上面的 lowdb 使用 console.log 将我取出 undefined ....

So I'm not sure why, but you have to remove a point on the road to lowdb files.所以我不知道为什么,但你必须在通往 lowdb 文件的道路上删除一个点。

Code not working:代码不起作用:

const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('../db.json')
const db = low(adapter)
const adapter2 = new FileSync('../users.json')
const users = low(adapter2)
const fetch = require('node-fetch');
const config = require('../config.json');
const api = config.api;

Code after modification and functional:修改后的代码和功能:

const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('./db.json')
const db = low(adapter)
const adapter2 = new FileSync('./users.json')
const users = low(adapter2)
const fetch = require('node-fetch');
const config = require('../config.json');
const api = config.api;

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

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