I am coding my own discord bot, and making warn system with quick.db
package, and having a problem. If I warn a person 2 times, and unwarn him, It removes all the warns of the user. The code is:
//I have imported discord.js and others. This is only the part of warn and unwarn command.
if(command === "warn" ) {
const db = require('quick.db')
const Wuser = message.mentions.users.first();
const member = message.guild.member(Wuser)
if(!message.member.hasPermission("MANAGE_MESSAGES"))
return message.channel.send("You dont have the permission to warn anyone").then(msg => {
msg.delete({ timeout: 10000 })
})
if (!Wuser) return;
if(Wuser.id === message.author.id) return message.channel.send("You cant warn yourself").then(msg => {
msg.delete({ timeout: 10000 })
})
if(Wuser.id === client.user.id) return message.channel.send("You cant warn me").then(msg => {
msg.delete({ timeout: 10000 })
})
db.add(`warn.${Wuser.id}`, 1);
const data = db.get(`warn.${Wuser.id}`);
if(data === undefined ) {
let data = 0
}
message.channel.send(`${Wuser} you are warned. Additional infractions may result in a mute. You have ${data} warns.`)
logchannel.send(`${Wuser} is warned. He have ${data} warns. He is warned by ${message.author}.`)
blogchannel.send(`${Wuser} is warned. He have ${data} warns. He is warned by ${message.author}.`)
}
if(command === "unwarn" ) {
if(!message.member.hasPermission("MANAGE_MESSAGES"))
return message.channel.send("You dont have the permission to unwarn anyone").then(msg => {
msg.delete({ timeout: 10000 })
})
const db = require('quick.db')
let Wuser = message.mentions.users.first();
let member = message.guild.member(Wuser)
if (!Wuser) return;
if(Wuser.id === message.author.id) return message.channel.send("You cant unwarn yourself").then(msg => {
msg.delete({ timeout: 10000 })
})
if(Wuser.id === client.user.id) return message.channel.send("You cant unwarn me").then(msg => {
msg.delete({ timeout: 10000 })
})
db.delete(`warn.${Wuser.id}`)
const data = db.get(`warn.${Wuser.id}`)
message.channel.send(`${Wuser} is unwarned. ??`)
logchannel.send(`${Wuser} is unwarned by ${message.author}.`)
blogchannel.send(`${Wuser} is unwarned by ${message.author}.`)
}
if(command === "userlog") {
if(!message.member.hasPermission("MANAGE_MESSAGES"))
return message.channel.send("Why are you looking other's user log?").then(msg => {
msg.delete({ timeout: 10000 })
})
let Wuser = message.mentions.users.first()
let member = message.guild.member(Wuser)
if (!Wuser) return message.channel.send("User not specified").then(msg => {
msg.delete({ timeout: 10000 })
})
const db = require('quick.db')
const data = db.get(`warn.${Wuser.id}`)
let logEmbed = new MessageEmbed()
.setTitle(`Log of ${Wuser.tag}`)
.setDescription(`${Wuser} currently have ${data} warns.`)
.setThumbnail(member.user.displayAvatarURL)
message.channel.send(logEmbed)
logchannel.send(`${message.author.tag} used **.userlog** command.`)
}
What I have to edit the code? Thanks in advance.
question from:
https://stackoverflow.com/questions/65661262/quick-db-unwarn-command-unwarns-all-the-warns-in-a-member 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…