Search code examples
javascriptnode.jsdiscord.js

Remove a value from a json file


I want to make a unwhitelist command, if user is mentioned or you give the id, it will remove the id from the json file (it don't check if there is the id), do you have any idea for remove the id ?

I use discord.js v13.6.0

This is my code:

if (message.content.startsWith(prefix + "unwhitelist")) {
  if (!args[0]) return message.edit(":x: **Veuillez mentionner quelqu'un**")
  let user = message.mentions.users.first() || client.users.cache.get(args[0])
  if (!user) return message.edit(":x: **Veuillez mentionner quelqu'un**")
delete crow["users"][user.id]
savecrow()
message.edit("`"+user+"` n'est plus whitelist")
} 

and the json file is like that:

{"users": ["user1","user2"]}

Solution

  • I found it

      crow["users"].splice(crow["users"].indexOf(user.id), 1);