【发布时间】:2019-12-28 23:52:33
【问题描述】:
有没有办法忽略特定的机器人消息?
我正在尝试这个。
if (message.author.bot) return;
但这忽略了所有机器人消息,我只想忽略具体消息,而不是所有消息。
【问题讨论】:
-
通过设置一些条件
标签: javascript node.js bots discord.js
有没有办法忽略特定的机器人消息?
我正在尝试这个。
if (message.author.bot) return;
但这忽略了所有机器人消息,我只想忽略具体消息,而不是所有消息。
【问题讨论】:
标签: javascript node.js bots discord.js
试试类似的东西
//noReply should contain unanswered messages
const noReply = [ 'messages noReply','noReply exp','noReply hello','nop noReply','xxx','one a one','lazy' ];
const mab = message.content;
if (noReply.some(msgs => msgs == mab)) return;
或使用过滤器,切换
【讨论】:
message.content,所以我在这里有点困惑。
const blacklist = ['test', 'hello', 'world']
if(blacklist.includes(message.content)) return
上面的代码只在消息完全按照列表中的类型输入时才会忽略(区分大小写)。如果您希望它不区分大小写,请将 message.content 更改为 message.content.toLowerCase() 并确保您的列表仅包含小写版本。
如果你想检查每个单词,你可以简单地使用一个循环遍历每个单词。
const blacklist = ['test', 'hello', 'world']
const words = message.content.split(' ')
words.forEach(word => {
if(blacklist.contains(word)) return
})
【讨论】:
以特定短语开始每条列入黑名单的消息,或在blacklist 数组中保留它们的列表
// Inside of message event
const blacklist = ['noreply', 'dnr']; // These are case sensitive
if (message.author.bot) { // and may contain spaces
// Otherwise anyone could start their message with "noreply" and be ignored
if (blacklist.some(phrase => message.content.startsWith(phrase))) return;
// .... continue with rest of code
}
注意:不要只使用blacklist.some(message.content.startsWith),因为它会根据blacklist中短语的索引跳过一些单词
【讨论】: