default value

This commit is contained in:
Erik 2022-06-29 10:06:38 +03:00
parent c981af74c1
commit 28285fbe69
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -128,7 +128,7 @@ class GuildWrapper {
async fetchData() {
if(this._data) return this._data;
const data = await this.client.mongodb.guilds.findOne({ guildId: this.id });
if (!data) return null;
if (!data) return {};
if (data._version === '3.slash') {
const keys = Object.keys(this.defaultConfig);
const settings = {};
@ -148,7 +148,7 @@ class GuildWrapper {
async settings(forceFetch = false) {
if (this._settings && !forceFetch) return this._settings;
const data = await this.fetchData() || {};
const data = await this.fetchData();
const { settings } = data;
// const settings = await this.client.storageManager.mongodb.guilds.findOne({ guildId: this.id });
// if(this._settings instanceof Promise) this._settings = await this._settings || null;
@ -160,7 +160,7 @@ class GuildWrapper {
async updateData(data) {
try {
await this.client.mongodb.guilds.updateOne({ guildId: this.id }, { _version: configVersion, ...data });
this._data = { ...this._data, ...data };
this._data = { ...this._data, ...data, _version: configVersion };
this._storageLog(`Database update: Data (guild:${this.id})`);
} catch (err) {
this._storageError(err);