问题描述
我正在使用命令处理来处理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())
...
这是我的db.json:
{
"numbers": [
{
"test": "1234"
}
]
}
当我单独使用console.log db时,它会将我带出该对象,但是像上面那样尝试用lowdb进行console.log时,它会将我带出未定义的...。
解决方法
所以我不确定为什么,但是您必须删除通往lowdb文件的路径。
代码不起作用:
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;
修改后的代码和功能性
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;