1

Im trying to code my discord bot to prevent advertising other discords. I've read a lot on this site, but can't find the solution. I want the bot to search for discord invites in a message, and if this link is not posted by a member that has the kick permission, then it should delete the invite.

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));
    }}
Milo
  • 13
  • 1
  • 4
  • What is the problem? What error are you receiving? – cb64 Feb 26 '19 at 18:46
  • The bot is not deleting or sending a message to the user that post's a discord link, regardless they have/have not the kick permission. Edit: And there is no error's in the console. – Milo Feb 26 '19 at 18:50
  • Does your bot have moderator permissions to delete and send messages? Does the code you posted actually reach the if statement before the delete message? `Console.log` a message to see if you're hitting each conditional. Your code looks perfectly fine. – cb64 Feb 26 '19 at 18:55
  • My bot has moderator rights yes. https://ibb.co/N990BhB <-- screenshot – Milo Feb 26 '19 at 18:59
  • So, i just did the console.log, and im getting 0 hits. – Milo Feb 26 '19 at 19:11
  • I figured it out, see my answer. – cb64 Feb 26 '19 at 19:16
  • Solved. Had it after a. if(!message.content.startsWith(config.prefix)) return; – Milo Feb 26 '19 at 19:17

1 Answers1

0

Includes only accepts one condition. You have to use separate include statements if you're using || for each of the strings you're trying to catch. If you want to check for multiple conditions try using some()

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));
  }
}
cb64
  • 825
  • 8
  • 16