Answer the question
In order to leave comments, you need to log in
How to limit bot promotion?
const mongo = require('./mongo')
const profileSchema = require('./schemas/profile-schema')
module.exports = (client) => {
client.on('message', (message) => {
const { guild, member } = message
addXP(guild.id, member.id, 23, message)
})
}
const getNeededXP = (level) => level * level * 100
const addXP = async (guildId, userId, xpToAdd, message) => {
await mongo().then(async (mongoose) => {
try {
const result = await profileSchema.findOneAndUpdate(
{
guildId,
userId,
},
{
guildId,
userId,
$inc: {
xp: xpToAdd,
},
},
{
upsert: true,
new: true,
}
)
let { xp, level } = result
const needed = getNeededXP(level)
if (xp >= needed) {
++level
xp -= needed
message.reply(
`You are now level ${level} with ${xp} experience! You now need ${getNeededXP(
level
)} XP to level up again.`
)
await profileSchema.updateOne(
{
guildId,
userId,
},
{
level,
xp,
}
)
}
} finally {
mongoose.connection.close()
}
})
}
module.exports.addXP = addXP
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question