Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
Discord.js v12.5.3 Anyone know why this doesn't work?

EDIT: ColinD solved my problem but now the message doesn't delete and I have no idea why the message wont delete because its worked for me before with bots

Code:

const discord = require('discord.js')
const newEmbed = require('embedcord')
const randomHex = require('random-hex')

module.exports = (client, message, options) => {

let links = require('./links.json')
let foundLink = false
let banReason = (options && options.banReason) || 'Sent a phishing link.'
let logs = (options && options.logs)
let member = message.mentions.members.first()

for(var i in links) {
  if(message.content.toLowerCase().includes(links[i])) foundLink = true
}

if(foundLink) {
  if(message.author.hasPermission('ADMINISTRATOR'))
    return
  message.delete()
  member.ban({reason: banReason})
  const embed = newEmbed(
    '**Member Banned**',
    `${randomHex.generate()}`,
    `Member was banend for ${options.banReason}`
  )
  logs.send(embed)
}
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your return position might be preventing anything below if from running try changing this

    if (foundLink) {
        if (message.author.hasPermission('ADMINISTRATOR')) return;
        const embed = newEmbed(
            '**Member Banned**',
            `${randomHex.generate()}`,
            `Member was banend for ${options.banReason}`
        );

        message.delete();
        member.ban({
            reason: banReason
        });
        logs.send(embed);
    }

Or this if you want if/else

    if (foundLink) {
        if (message.author.hasPermission('ADMINISTRATOR')) {
            return;
        } else {
            const embed = newEmbed(
                '**Member Banned**',
                `${randomHex.generate()}`,
                `Member was banend for ${options.banReason}`
            );

            message.delete();
            member.ban({
                reason: banReason
            });
            logs.send(embed);
        }
    }
about 4 years ago · Juan Pablo Isaza Report

0

EDIT: ColinD solved my problem but now the message doesn't delete and I have no idea why the message wont delete because its worked for me before with bots

foundLink variable is unnecessary, you can move your code inside the loop.

Use message.member.hasPermission() instead of message.author.hasPermission().

Example code for v12.5.3(Message Event):

client.on('message', (message) => {
  if (message.author.bot) return; // Ignore bot messages

  const { member, channel, guild } = message; // Get the message author, channel, and guild
  if (!member || !channel || !guild) return;  // Ignore messages without a member, channel or guild

  const { links } = require('./links.json');  // Get links from json file

  for (let i = 0; i < links.length; i++) {   // Check if the message contains a link in the links.json file
    if (message.content.toLowerCase().includes(links[i])) {  // If the message contains a link
      if (member.hasPermission('ADMINISTRATOR')) return; // If the member has the administrator permission, don't ban them

      const banReason = 'Sent a phishing link';   // Reason for the ban
      message.delete();  // Delete the message
      guild.member(member).ban({ reason: banReason });   // Ban the member
      channel.send(`${member.displayName} has been banned for sending a phishing link.`)  // Send a message to the channel
      break;
    }
  }
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!