Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda