Quick.db unwarn 命令取消警告成员中的所有警告

Posted

技术标签:

【中文标题】Quick.db unwarn 命令取消警告成员中的所有警告【英文标题】:Quick.db unwarn command unwarns all the warns in a member 【发布时间】:2021-04-16 01:34:04 【问题描述】:

我正在编写自己的不和谐机器人,并使用quick.db 包制作警告系统,但遇到了问题。如果我警告一个人 2 次,并且不警告他,它会删除用户的所有警告。代码是:

//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.`)
   

我必须编辑什么代码?提前致谢。

【问题讨论】:

【参考方案1】:

在 unwarn 命令中

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

而不是这个添加到数据库

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

或从值中减去

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

【讨论】:

以上是关于Quick.db unwarn 命令取消警告成员中的所有警告的主要内容,如果未能解决你的问题,请参考以下文章

Quickdb add 不是 Quick.db 的函数错误

排行榜命令中未定义的用户名 [ quick.db / discord.js ]

尝试关闭并打开命令 quick.db

将用户名存储在 quick.db 数据库中

为啥我没有收到关于在 C# 8 中使用结构的类成员可能取消引用 null 的警告?

在 discord.js 中,使用 quick.db 我想为我的机器人的货币系统创建一个卖出命令