检查 discord link 并删除

Check for discord link and delete

我正在尝试编写我的 discord 机器人代码,以防止宣传其他 discord。 我在这个网站上阅读了很多,但找不到解决方案。 我想让机器人在消息中搜索不和谐的邀请,如果这个 link 不是由拥有踢权限的成员发布的,那么它应该删除邀请。

if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) { //if it contains an invite link
        if(!message.member.hasPermission("KICK_MEMBERS")) {
            message.delete() //delete the message
            .then(message.member.send(ms.INVITELINK));
    }}

包括只接受一个条件。如果您对要捕获的每个字符串使用 ||,则必须使用单独的 include 语句。如果您想检查多个条件,请尝试使用

if (message.content.includes('discord.gg/') || message.content.includes('discordapp.com/invite/')) { //if it contains an invite link
  if (!message.member.hasPermission("KICK_MEMBERS")) {
    message.delete() //delete the message
      .then(message.member.send(ms.INVITELINK));
  }
}