Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda