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

312
Visualizações
How would i go about adding arguments to my discord.js commands?

What would be the best way to add arguments to my discord commands? e.g, !ban {username} Any help would be greatly appreciated!

const Client = new Discord.Client({
    intents: ["GUILD_MESSAGES", "GUILDS"],
});

const botOptions = {
    token: "",
    prefix: ['!','.'],
    commands: [
        {
            name: ['joined','j'],
            roles: ['@everyone'],
            channels: [],
            method: (msg) => require('./userJoined')(msg),
        },
    ],
};

Client.on("messageCreate", (msg) => {
    const prefix = msg.content.split('')[0];
    const commandName = msg.content.split(prefix)[1].toLowerCase();
    const checkPrefix = botOptions.prefix.some((x) => x === prefix);
    const findCommand = botOptions.commands.find(command => command.name.includes(commandName));
    if (typeof findCommand !== 'undefined' && checkPrefix) {
        const { name, roles, channels, method } = findCommand;
        const rolePermission = msg.member.roles.cache.some(role => roles.includes(role.name.toLowerCase()));
        const channelPermission = channels.includes(msg.channelId);
        if (channelPermission || channels.length === 0 && rolePermission) {
            method(msg);
        }
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're trying to add args (arguments) you should first split the message into an array

    let messageArray = message.content.split(" ");

Now you just have an array full of arguments, the first argument in the messageArray variable is basically the command which is being executed, after that the rest are just the message args.

    let messageArray = message.content.split(" ");
    let cmd = messageArray[0]; // getting the command, this line can be removed
    let args = messageArray.slice(1)

In the example above we sliced the messageArray variable at its 2nd element which is the first argument of the message (not including the cmd).

So here is a small example how this works !mix 3845345343 4353943

3845345343 being args[0]
4353943 being args[1]

and so on if you have more args

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