所以我在代码上遇到了一些问题,我试图让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)})
}
它可以工作并向用户发送嵌入消息,并删除他们发送的消息。不知道这是怎么回事。提前致谢。
您将直接与数组进行比较,而不是检查message.author.id是否在数组中。
代替
if (message.author.id === blacklisted)
尝试
if (blacklisted.includes(message.author.id))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句