【发布时间】:2021-09-12 06:45:49
【问题描述】:
我的 javascript 机器人遇到了问题,如果该服务器还没有自定义前缀,则不会保存我的自定义前缀,如果有,它会正确更新。
await mongo().then(async (mongoose) => {
try {
let newprefix = content.replace(`${prefix}setprefix `, '')
await prefixSchema.findOneAndUpdate({_id: guild.id}, {_id: guild.id, prefix: newprefix})
.then(async () => {
console.log(`updated prefix for guild: ${guild.id}`)
await channel.send(`Succesfully updated prefix for this server to '${newprefix}'`)
message.guild.me.setNickname(`[${newprefix}] - Helix`)
})
.catch(async (err) => {
console.error(`failed to update prefix for guild: ${guild.id}\n${err}`)
await channel.send(`Failed to update prefix.`)
})
console.log("saved to db")
} catch {
console.log("Something went wrong while saving new prefix for a server.")
} finally {
mongoose.connection.close()
}
机器人确实会打印并发送它已成功更新前缀,但如果还没有 guild.id 的文档,则不会保存任何内容。我做错了什么,我该如何解决?
感谢阅读!
【问题讨论】:
标签: mongodb mongoose discord discord.js