0

我一直在使用 rethinkdb,由于它已经过时了,我想切换到 mongodb。在我的prefix命令下,我不断收到该错误,这是我的代码:

const { Guild } = require('../../models/Guild');

async function prefixCommand (msg, args) {
    if (!msg.member.permissions.has('manageGuild') && !this.config.options.devs.includes(msg.author.id)) {
        return msg.channel.createMessage('You need `manageGuild` to be able to use this command!');
    }

    Guild.findOne({ guildID: msg.channel.guild.id }, function(err, doc) {
        let prefixConfig;

        if (!args[0]) {
            return msg.channel.createMessage('Prefix is a required argument!\nUsage: `prefix <prefix>`');
        }
        if (args.join(' ').length > 32) {
            return msg.channel.createMessage(`Your prefix cannot be over 30 characters long! You are ${args.join(' ').length - 32} characters over the limit.`);
        }
        if (doc.prefix === args.join(' ').toLowerCase()) {
            return msg.channel.createMessage(`\`${args[0]}\` is already your current prefix.`);
        }

        //prefixConfig.prefix = args.join(' ');
        doc.prefix = args.join(' ');
        doc.save();
        //await this.m.updateGuild(msg.channel.guild.id, prefixConfig.prefix);
        msg.channel.createMessage(`Prefix has been set to \`${prefixConfig}\``);
    });
}

而公会是这样的:

const mongoose = require('mongoose');

const guildSchema = new mongoose.Schema({
    guildID: String,
    guildName:String,
    ownerID: String,
    prefix: { 
        type: String, 
        default: '>' 
    }
});

module.exports = mongoose.model('Guild', guildSchema)

我似乎无法弄清楚是什么问题。任何帮助表示赞赏!

4

1 回答 1

2

只需将您的要求更改为const Guild = require('../../models/Guild');

您正在导出模型作为默认值,/models/Guild但需要它,就像它的命名导出一样module.exports = { Guild }

于 2021-06-22T13:24:17.787 回答