出现此错误。我正在尝试编写一个 /prefix [new prefix] 命令并且它会更新,这是我的错误:mongoose:要创建新的 ObjectId 请尝试使用 Mongoose.Types.ObjectId
而不是使用 Mongoo Trace at ObjectId (C:\Users\dakot\Desktop\SAFBOT\node_modules\mongoose\lib\schema\objectid.js:35:1 at Object.<anonymous> (C:\Users\dakot\Desktop\SAFBOT\models\guild.js:4:32) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Module.require (internal/modules/cjs/loader.js:952:19) at require (internal/modules/cjs/helpers.js:88:18) at Object.<anonymous> (C:\Users\dakot\Desktop\SAFBOT\commands\prefix.js:2:15) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Module.require (internal/modules/cjs/loader.js:952:19) at require (internal/modules/cjs/helpers.js:88:18) at module.exports (C:\Users\dakot\Desktop\SAFBOT\handlers\command_handler.js:7:25) C:\Users\dakot\Desktop\SAFBOT\node_modules\mongoose\lib\schema.js:475 TypeError: Invalid value for schema path
_id`,得到值“未定义”
在 Schema.add (C:\Users\dakot\Desktop\SAFBOT\node_modules\mongoose\lib\schema.js:475:13)
在新架构 (C:\Users\dakot\Desktop\SAFBOT\node_modules\mongoose\lib\schema.js:129:10)
在 Mongoose.Schema (C:\Users\dakot\Desktop\SAFBOT\node_modules\mongoose\lib\schema.js:94:12)
在对象。 (C:\Users\dakot\Desktop\SAFBOT\models\guild.js:3:30)
在 Module._compile (internal/modules/cjs/loader.js:1063:30)
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
在 Module.load (internal/modules/cjs/loader.js:928:32)
在 Function.Module._load (internal/modules/cjs/loader.js:769:14)
在 Module.require (internal/modules/cjs/loader.js:952:19)
在要求 (internal/modules/cjs/helpers.js:88:18)
在对象。 (C:\Users\dakot\Desktop\SAFBOT\commands\prefix.js:2:15)
在 Module._compile (internal/modules/cjs/loader.js:1063:30)
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
在 Module.load (internal/modules/cjs/loader.js:928:32)
在 Function.Module._load (internal/modules/cjs/loader.js:769:14)
在 Module.require (internal/modules/cjs/loader.js:952:19)
我的代码: Prefix.js 文件:
const Guild = require('../models/guild');
module.exports = {
name: 'prefix',
description: 'Sets guild prefix',
async execute (client, message, args, Discord, cmd, prefix){
const settings = await Guild.findOne({
guildID: message.guild.id
}, (err, guild) => {
if (err) console.error(err)
if(!guild){
const newGuild = new Guild({
_id: mongoose.Schema.Types.ObjectId(),
guildID: String,
guildName: String,
prefix: String
})
newGuild.save()
.then(result => console.log(result))
.catch(err => console.error(err));
return message.channel.send('This server was not in our database! We have added it in, please re-use the command for it to work...').then(m => m.delete({timeout: 10000}))
}
});
await settings.updateOne({
prefix: args[0]
});
return message.channel.send(`Prefix has been edited to ${args[0]}`)
}
}```