So, i'm trying to make a simple Discord Bot using javascript, and I want to detect if a player username is on the banned list. I have an array
var banned = ['Andrew','David']
and an if
if (message.author.username instanceof banned) {.....
but when I run it, it outputs
if (message.author.username instanceof banned)
^
TypeError: Right-hand side of 'instanceof' is not callable
What can I do?
This is not what instanceof
is for. instanceof
is used to see if an object is an instance of a specific constructor (ex: banned instanceof Array
).
If you just want to see if an element is in an array, you can use .indexOf()
.
if(banned.indexOf(message.author.username) != -1)
instanceof
is used to check if an object is an instance of a class. What you want to do is to check if a string is in an array like this:
if (banned.indexOf(message.author.username) >= 0) {...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With