提问者:小点点

阻止某些通道中的消息discord.js


我想在某些频道屏蔽某些信息,但用我现在的代码,这些词在不和的每个频道都被屏蔽了。我只想在数据库中的频道中阻止这个词。有办法做到这一点吗?

  if (message.content.includes('discord.gg/'||'discordapp.com/invite/'||'discord.me/'||'discord.com/')) 
    return blacklist.set(message.author.id, 'blacklisted');

共2个答案

匿名用户

你可以做点什么。

let forbiddenWords = ["discord.gg", "discordapp.com/invite"];
let forbiddenChannels = ["a channel id", "another one"];

for (var i = 0; i < forbiddenWords.length; i++) {
    if (message.content.includes(forbiddenWords[i])) {
        if (forbiddenChannels.includes[message.channel.id]) {
            return blacklist.set(message.author.id, 'blacklisted');
        }
    }
}

匿名用户

您需要做的是检查消息所来自的通道是否实际上是您想要阻止单词的通道。您可以使用channel.id参数执行此操作。

if (message.channel.id === "your id here") {
    // the rest of your code
}