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

165
Visualizações
while loop, specify arguments in any order?
    const logs = [
        "channelCreate",
        "channelDelete",
        "channelPinsUpdate",
        "channelUpdate",
    ]

    let bee = logs.length;

    for (let i = 0; i < bee; i++) {
        while (args[1] == logs[i]) {
            if (args[1].startsWith("channelCreate")) {
                db.remove_logging(message.guildId, args[1])
                args.splice(1, 1);
            } else if (args[1].startsWith("channelDelete")) {
                db.remove_logging(message.guildId, args[1])
                args.splice(1, 1);
            } else if (args[1].startsWith("channelPinsUpdate")) {
                db.remove_logging(message.guildId, args[1])
                args.splice(1, 1);
            } else if (args[1].startsWith("channelUpdate")) {
                db.remove_logging(message.guildId, args[1])
                args.splice(1, 1);
            } else {
                return message.channel.send({ content: "log typ error" })
            }
        }
    }

I'm trying to build a command, that looks something like this: p!set log channelCreate channelDelete channelPinsUpdate channelUpdate

I can type these arguments channelCreate channelDelete channelPinsUpdate channelUpdate but only in the correct order, so that everything is removed from the database. But I want that it doesn't matter how to specify the arguments, e.g. channelPinsUpdate channelCreate channelUpdate channelDelete

I suspect I am doing something wrong, but unfortunately I don't know what

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

0

All you are doing is removing the log from db with same arguments so you can just do this instead:

const logs = [
    "channelCreate",
    "channelDelete",
    "channelPinsUpdate",
    "channelUpdate",
];

if (!logs.includes(args[1])) return message.channel.send({ content: "log typ error" });

db.remove_logging(message.guildId, args[1]);

The code checks for valid log from logs array and if args[1] is invalid, it returns error. Otherwise, it executes remove_logging method of db.

about 4 years ago · Juan Pablo Isaza Relatório

0

It's the logic of your loops that isn't consistent. You must first loop over the arguments and thus test if each of them is a log and thus execute your deletion. In this way, all the arguments will be compared to the logs and it doesn't matter the order of the arguments. Try this:

for (let i = 1, arg; arg = args[i]; ++i) {
    if (arg.startsWith("channelCreate")) {
        db.remove_logging(message.guildId, arg)
    } else if (arg.startsWith("channelDelete")) {
        db.remove_logging(message.guildId, arg)
    } else if (arg.startsWith("channelPinsUpdate")) {
        db.remove_logging(message.guildId, arg)
    } else if (arg.startsWith("channelUpdate")) {
        db.remove_logging(message.guildId, arg)
    } else {
        return message.channel.send({ content: "log typ error" })
    }
}
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