Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
880 views
in Technique[技术] by (71.8m points)

discord.js - Quick.db unwarn command unwarns all the warns in a member

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the unwarn command

db.delete(`warn.${Wuser.id}`)

Instead of this add to the db

          db.add(`warn.${Wuser.id}`, -1);

or subtract from the value

          db.subtract(`warn.${Wuser.id}`, 1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...