机器人检查多个链接

时间:2020-05-24 06:51:19

标签: javascript node.js bots discord discord.js

我发出了反邀请命令,但是该漫游器没有删除在启用该命令的行会中发送的链接。 v12.2

if(message.content.includes(["https://discord.gg/", "https://discord.io/", "https://discord.me/"]))

2 个答案:

答案 0 :(得分:0)

您需要检查message.content是否分别包含每种可能性,因为该方法一次只能接受一个字符串。

答案 1 :(得分:0)

可以将.some()与要检查indexOf的回调一起使用,这很短。

// mock
const message = {
  content: 'Come join my room https://discord.gg/1234'
}

//
const links = ["https://discord.gg/", "https://discord.io/", "https://discord.me/"]

//
if (links.some(el => message.content.indexOf(el) !== -1)) {
 // link/domain matched
}

还有其他方法也可以做到这一点,例如简单的正则表达式匹配。