简体   繁体   English

黑名单用户 ID discord.js

[英]Blacklist user IDs discord.js

How do I make my bot ignore users that I've added to a list?如何让我的机器人忽略我添加到列表中的用户? I'm new to this.我是新手。 I tried a few other ways I found on this site but I don't know how to add them to my code, I tried and failed.我尝试了在这个网站上找到的其他一些方法,但我不知道如何将它们添加到我的代码中,我尝试过但失败了。

Try this:尝试这个:

let blacklistUser = ['UserID1','UserID2']

if(!blacklistUser.includes(user.id){
    ///your code
}

Here is a short explanation of the code:以下是代码的简短说明:

let blacklistUser = ['UserID1','UserID2'] This is an array with the IDs of the blacklisted Users let blacklistUser = ['UserID1','UserID2']这是一个包含黑名单用户 ID 的数组

if(!blacklistUser.includes(user.id){}

The !这 ! means "NOT" and blacklistUser.includes(user.id) is a funcion that checks if an array(blacklistUser) includes an object(user.id)表示“NOT”, blacklistUser.includes(user.id)是一个函数,用于检查数组(blacklistUser) 是否包含对象(user.id)

You should replace user.id with the needed variable.您应该将user.id替换为所需的变量。 For example in a message event it would be: message.author.id .例如,在消息事件中,它将是: message.author.id

I hope I could help you, to fix this problem.我希望我能帮助你,解决这个问题。

const ids = []

if(ids.has(id)) {
 console.log('This person is on black list')
} else {
 return
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM