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

216
Visualizações
Discord.JS v13 Search a List for a specific key word

I wanted to write a command to check if a specific user is part of a ban list in my server. Unfortunately it always does the stuff in the else loop. I hope you can help.

const Discord = require('discord.js');
const ms = require('ms');
const { Permissions } = require("discord.js");
const { MessageEmbed } = require("discord.js");
//const config = require("./config.json");


module.exports = {
    name: 'check',
    category: "Moderation",
    description: 'Checkt ob ein User gebannt ist',

    run: async(client,message,args,guild) => {
        let arg = message.content.split(" ")
        let banlist = client.channels.cache.get('CHANNELID')
        let check = arg[1]

        message.delete()

        if (!arg[1]) {
            return message.channel.send({content :"Please specify a user to check!"}).then((message) => setTimeout(() => message.delete(), 10000)).catch(err => {
                console.error(err);
            });
        }

        banlist.messages.fetch({limit : 30}).then(messages => {
            let positive = messages.filter(msgs => msgs.content.includes(check))
            if(!positive) {
                message.channel.send({content :"This user is not banned!"}).then((message) => setTimeout(() => message.delete(), 10000)).catch(err => {
                    console.error(err); 
                });
            }
            else {
                message.channel.send({content :`This user is banned.`}).then((message) => setTimeout(() => message.delete(), 10000)).catch(err => {
                    console.error(err); 
                });
            }
        })


        }
};

I know there are methods to check the servers banned user list but not everyone on the list in the channel is banned on discord. So I can't do that. To sum that up. I tried to do a command, which checks a channel for a specific key word and returns differing statements, whether he found that key word or not.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

filter() returns an empty array if it finds nothing. You can use:

if(positive.length === 0) {
// ...
}
else {
// ...
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Since you're looking for a boolean, use Array.some()

const positive = messages.some(msg => msg.content.includes(check));

.filter() is intended for returning a new array

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