I want to make a quest system for my discord.js bot and im making some code that runs everytime a user messages.
async function quests() {
const {
message,
bot,
Discord
} = require('../index')
const Yen = require('../models/yen')
var user = message.author;
const yenData = await Yen.findOne({
guildID: bot.guilds.cache.get(message.guild.id).id,
userID: user.id
}, (err, data) => {
if (err) console.log(err)
if (!data) return;
})
}
module.exports.quests = quests;
This code right now runs every time someone messages but I want it so if a condition is met like if a user gets 200 coins they get an extra reward of maybe a weapon.
I can’t just do:
if(coins === 200) {
//give weapon script
}
because then it would keep giving the person a weapon every time he messages until he hits 201+ coins. How can I make it so it only sends once?
Wait, so when you message once, you get multiple weapons right? Or every message gives you the weapon? Sorry I am bit confused.
Well you either have to take out coins or store a data that tells server that user already has a weapon and not give it again. If it’s the second case.
I already i have a mongodb database for all that. What im saying is that the code that i showed is in the message function so it’s run everytime a message is sent in the server. I want to make it so it finds the message authors data (if theres no data for the user its returned) and checks if they have 200 coins (if not it returns). If they have 200 coins then it will give them a weapon or something. The thing is, since it’s checked every message, if they message again right after with 200 coins, it’ll see that they have 200 coins and give them another weapon, I don’t want that to happen. I want it so it’s only a one time thing.
Welp, that’s gonna be a pain, thanks anyways. I might come back to the quest system later, lol. I already knew i had to store it somewhere but i wanted to see if there was any other way that would be simpler…