我想阻止某些频道中的某些消息,但是使用我现在拥有的代码,单词在Discord的每个频道中都被阻止。我只想在数据库中的通道中阻止此单词。有办法吗?
if (message.content.includes('discord.gg/'||'discordapp.com/invite/'||'discord.me/'||'discord.com/'))
return blacklist.set(message.author.id, 'blacklisted');
答案 0 :(得分:1)
这是您可以做的。
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');
}
}
}
答案 1 :(得分:0)
您需要做的是检查消息所来自的通道是否实际上是您要阻止单词的通道。您可以使用channel.id
参数来实现。
if (message.channel.id === "your id here") {
// the rest of your code
}
编辑:
如果要阻止多个频道,则应使用
let YourDatabaseForChannels = ["Your channel", "Your other channel"];
if (YourDatabaseForChannels.includes(message.channel.id)) {
// the rest of your code
}