如何将新成员的 ID 与数据库中的 ID 进行比较?

How do I compare the ID of the new members with the ones in the database?

我正在尝试在拥有此角色的成员离开服务器并再次加入角色时发出监狱命令,我希望当新成员进入服务器时将他们的 ID 与数据库中的 ID 进行比较,如果是真的,它又给了一个角色。我的代码:

client.on("guildMemberAdd",async (member)=>{
     let injail = await db.fetch(`ja_${member.guild.id}`)
     let role = msg.guild.roles.cache.find(n => n.name === 'Jail');
     if(member.guild.id = injail){
    member.roles.remove(user.roles.cache)
    member.roles.add(role)
     }
  });

client.on('message', msg => {
if(msg.content.startsWith(prefix + 'jail')){
    if(!owners.includes(msg.author.id)) return msg.channel.send("**You Dont Have Perms **")
    if(!msg.channel.guild) return;
    var logChannel = msg.guild.channels.cache.find(channel => channel.id === logID)//LOG
   
  let jailRole = msg.guild.roles.cache.find(n => n.name === 'Jail');
  let user = msg.mentions.members.first() //You can change this to an ID
  let args = msg.content.split(" ").slice(1).join(" ")
 
  if(!args[0]) return msg.channel.send('**:x: Please Mention A User**')
  if(user.hasPermission("ADMINISTRATOR")) return msg.channel.send("**Im NOT Allowed To Do This **")
  
  let there = db.get(`jl_${msg.guild.id}_${user}`, user.id)
  if (there) return msg.channel.send('**This User AlREADY In Jail ⛔**')
 
  msg.channel.send(`**ADDED ${user} to the Jail! ✅**`)
  db.set(`jl_${msg.guild.id}_${user}`, user.id)
  user.roles.remove(user.roles.cache)
  user.roles.add(jailRole)
 
   
  let embed = new Discord.MessageEmbed()
        .setTitle('Jail System')
        .setAuthor(msg.author.tag,msg.author.avatarURL({dynamic:true}))
        .addField("Status",`JOINED THE JAIL `)
        .addField("User",`<@${user.id}> (ID: ${user.id})`)
        .addField("By",`<@${msg.author.id}> (ID: ${msg.author.id})`)
        .setTimestamp()
      logChannel.send(embed)
    }
   
});

每当人们获得“监狱”角色时,将“是”保存到数据库中。 并像上面那样检查条件。

这里给出示例代码:

// when people gets jail role, add following code:
db.set(`ja_${msg.guild.id}_${user}`, "yes") // or you can simply use boolean operator

// when guildMemberAdd event triggers check condition:
let condition = db.fech(`ja_${member.guild.id}_${member.user.id}`)

if(condition === "yes"){
    // write code to add "jail" role to the member
}
else{
    // your other code
}

此外,无论何时从成员中删除监狱角色,都不要忘记在数据库中设置“否”。