Javascript 如何使用discordjs忽略特定于bot的消息
有没有办法忽略特定的bot消息 我正在试着用这个Javascript 如何使用discordjs忽略特定于bot的消息,javascript,node.js,bots,discord.js,Javascript,Node.js,Bots,Discord.js,有没有办法忽略特定的bot消息 我正在试着用这个 if(message.author.bot)返回 但这会忽略所有bot消息,我只想忽略特定消息,而不是所有消息。试试类似的方法 //noReply should contain unanswered messages const noReply = [ 'messages noReply','noReply exp','noReply hello','nop noReply','xxx','one a one','lazy' ]; con
if(message.author.bot)返回代码>
但这会忽略所有bot消息,我只想忽略特定消息,而不是所有消息。试试类似的方法
//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;
或者使用过滤器,切换开关
//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;
const blacklist = ['test', 'hello', 'world']
if(blacklist.includes(message.content)) return
或使用过滤器、开关
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
})
上述代码仅在消息的类型与列表中的类型完全相同(区分大小写)时才会忽略。如果希望它不区分大小写,请将message.content
更改为message.content.toLowerCase()
,并确保列表仅包含小写版本
如果要检查每个单词,只需在每个单词之间使用循环即可
const blacklist = ['test', 'hello', 'world']
const words = message.content.split(' ')
words.forEach(word => {
if(blacklist.contains(word)) return
})
以特定短语开始每个黑名单消息,或在黑名单
数组中保留它们的列表
//消息事件内部
常量黑名单=['noreply','dnr'];//这些是区分大小写的
if(message.author.bot){//和可能包含空格
//否则,任何人都可能以“noreply”开头,并被忽略
if(blacklist.some(短语=>message.content.startsWith(短语)))返回;
//..继续代码的其余部分
}
注意:不要只使用黑名单.some(message.content.startsWith)
,因为它会根据黑名单中短语的索引跳过一些单词
用特定短语开始每个黑名单消息,或在黑名单
数组中保留它们的列表
//消息事件内部
常量黑名单=['noreply','dnr'];//这些是区分大小写的
if(message.author.bot){//和可能包含空格
//否则,任何人都可能以“noreply”开头,并被忽略
if(blacklist.some(短语=>message.content.startsWith(短语)))返回;
//..继续代码的其余部分
}
注意:不要只使用黑名单.some(message.content.startsWith)
,因为它会根据黑名单中短语的索引跳过一些单词
通过设置一些条件通过设置一些条件来显示这是否有效?您从未使用过message.content
,所以我现在有点困惑。很抱歉,我错了。在message.author.bot中,正确的选项应该是message.content这是如何工作的?您从未使用过message.content
,所以我现在有点困惑。很抱歉,我错了。在message.author.bot中,正确的选项应该是message.content