Nodejs How To Put Multiple Id's Into An If
When I try to put multiple id's into an if it only registers the first one. if (message.author.id != '196568585202565121' || '110324497353052160') return message.reply('You don't h
Solution 1:
if (message.author.id != '196568585202565121' || '110324497353052160') return message.reply("You don't have the perms")
This states: If the message author's ID is not 196568585202565121 or 110324497353052160. What you want it to say is: if the message author's ID is not 196568585202565121 or if the message author's ID is not 196568585202565121.
Change up your line to:
if (message.author.id !== '196568585202565121' || message.author.id !== '110324497353052160')
Also notice that the != was replaced with a double equal. !==. In JavaScript, != is not strict enough. We need to use !==
Solution 2:
You have to make the comparison in both parts of the if like this:
if (message.author.id !== '196568585202565121' || message.author.id !== '110324497353052160') return message.reply("You don't have the perms")
You could also add the ids to an array and filter the array.
let arr = ['196568585202565121', '110324497353052160']
let filter = arr.filter ( e => e === message.author.id)
arr.length > 0return message.reply("You don't have the perms")
Solution 3:
You can use array with .includes()
method.
if(!['196568585202565121','110324497353052160'].includes(message.author.id)) {
// to the things...
}
Read more: Array.prototype.includes()
Solution 4:
In order return message if non of the id's match, do this:
if (message.author.id !== '196568585202565121' || message.author.id !== '110324497353052160') {
return message.reply("You don't have the perms");
}
Post a Comment for "Nodejs How To Put Multiple Id's Into An If"