Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!