所以,我正在尝试使用 javascript 制作一个简单的 Discord Bot,并且我想检测玩家用户名是否在禁止列表中。
我有一个数组
var banned = ['Andrew','David']
和一个如果
if (message.author.username instanceof banned) {.....
但是当我运行它时,它会输出
if (message.author.username instanceof banned)
^
TypeError: Right-hand side of 'instanceof' is not callable
我能做些什么?
最佳答案
这不是 instanceof
是为了。 instanceof
用于查看对象是否是特定构造函数的实例(例如:banned instanceof Array
)。
如果只想查看某个元素是否在数组中,可以使用 .indexOf()
.
if(banned.indexOf(message.author.username) != -1)
关于javascript - instanceof 的右侧不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43502288/