I’m trying to make a command where it updates a boolean in a specific server.
If someone types: !rating enable, it makes the “rating” section in the mongodb to true, and if they type: !rating disable, it makes the rating section false.
if (!args[0]) return message.reply(`Usage: ${prefix} <enable/disable>`)
if (args[0] === "enable") {
Data.findOne({
guildID: bot.guilds.cache.get(message.guild.id).id,
}, (err, data) => {
if (err) console.log(err);
if (!data) {
const newData = new Data({
guildID: bot.guilds.cache.get(message.guild.id).id,
rating: true
})
newData.save().catch(err => console.log(err));
message.reply(`Rating was enabled, new setting saved.`)
if (data) {
const newData = new Data({
guildID: bot.guilds.cache.get(message.guild.id).id,
rating: true
})
newData.update({rating: args[0]}).catch(err => console.log(err));
message.reply(`Rating was enabled, setting updated.`)
}
}
})
}
I want it so when someone does !rating enable it changes the mongodb to true.
Same thing, but if it’s !rating disable it changes the mongodb to false.
I want these to update everytime the server owner changes the rating.
My rating model:
const mongoose = require('mongoose')
const ratingSchema = mongoose.Schema({
guildID: String,
rating: Boolean
})
module.exports = mongoose.model("Rating", ratingSchema)