所以我在代码方面遇到了一些问题,我试图让message.author.id与const中的ID列表匹配,然后执行某些操作。
const blacklisted = ["644298972420374528", "293534327805968394", "358478352467886083"];
if (message.author.id === blacklisted) {
message.delete()
const blacklistedMSG = new Discord.RichEmbed()
.setColor('#ff0000')
.setTitle('Blacklisted')
.setDescription(`You are currently Blacklisted. This means you cannot send messages in Any server with this bot.`)
.setTimestamp()
.setFooter(copyright);
message.author.send(blacklistedMSG).then(msg => {msg.delete(30000)})
}
当我拥有这样的功能时,它不会执行任何操作,并且控制台中也不会出现任何错误。但是当代码是这样的时候:
if (message.author.id === "644298972420374528") {
message.delete()
const blacklistedMSG = new Discord.RichEmbed()
.setColor('#ff0000')
.setTitle('Blacklisted')
.setDescription(`You are currently Blacklisted. This means you cannot send messages in Any server with this bot.`)
.setTimestamp()
.setFooter(copyright);
message.author.send(blacklistedMSG).then(msg => {msg.delete(30000)})
}
它可以工作并向用户发送嵌入消息,并删除他们发送的消息。不知道这是怎么回事。预先感谢。
答案 0 :(得分:1)
您要直接与数组进行比较,而不是检查message.author.id是否在数组中。
代替
if (message.author.id === blacklisted)
尝试
if (blacklisted.includes(message.author.id))