javascript - 试图检测用户何时达到 100 条消息,然后重置,并将一个添加到 caseCount,但它不起作用,我没有收到任何错误
问题描述
这是在 Discord.js 中使用 MongoDB,所有这些代码都在消息事件中
所以在 MongoDB 中,我正在尝试查看某人是否有 100 条或更多消息,如果有,它会重置他们的 messageCount,并在 messageCount 的“caseCount”中添加一个,这就是我到目前为止所拥有的,但它没有t 工作,也没有给我一个错误:
if(profileData.messageCount >= 100) {
await Profiles.findOneAndUpdate(
{
userID: message.author.id,
},
{
$inc: {
messageCount: 0,
caseCount: + 1
}
}
)
}
解决方案
$inc
在 MongoDB 中,为文档的属性增加或添加某个值。您目前正在做的messageCount
是向其添加 0,使其保持相同的数量。我相信您正在寻找的是将$set
属性设置为所需值的关键字。
if (profileData.messageCount >= 100) {
await Profiles.findOneAndUpdate({
userID: message.author.id,
}, {
$set: {
messageCount: 0
}
$inc: {
caseCount: 1
}
})
}
推荐阅读
- mapbox - Mapbox Android - 如何在给定边界区域和缩放 lvl 的情况下访问矢量平铺数据?
- webpack - webpack 或 babel-loader 在 node_modules 中找不到模块,这是 node_modules 中另一个模块所需要的
- javascript - Javascript中的函数和括号
- javascript - 在 | 之间选择字符串 带有和不带有符号本身的符号
- java - 打算在 android studio 上使用 kotlin 不起作用
- javascript - 如何获取服务器中的所有表情符号并让机器人在聊天中发送表情符号
- java - Gitlab API 下载文件 + RestTemplate
- c++ - 如何在 C++ 中创建模板化包装类
- python-3.x - AttributeError:响应内容不是文本。问题是什么?
- python - 如何在for循环中创建列表?