Travis
Travis

Reputation: 7

Command arguments not running the rest of my code

I'm trying to make a warn command and my args aren't working and I have no idea why

client.on("message", message => {
    if(message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ + /g);
    const command = args.shift().toLowerCase();

    if(command === "warn"){
        if(message.member.hasPermission("KICK_MEMBERS")){
            if(!args[1]) return message.reply("Invalid Syntax: " + prefix + "warn <user> <reason>");
                console.log("this code should be run") //Nothing works here and below
                let userWarn = message.mentions.first();
                if(!userWarn) return message.reply("User not found!");
                let Warnreason = args.join(" ").slice(22);

                let warnEmbed = new Discord.MessageEmbed()
                    .setAuthor(message.author.username)
                    .setColor("#FFC300")
                    .addField("Warned user: ", userWarn)
                    .addField("Reason: " + Warnreason)

                message.channel.send(warnEmbed);
                }
             }
    })

Works if there are no args but when there are args it doesn't work as shown here. Also I'm getting no errors.

Upvotes: 0

Views: 159

Answers (1)

Syntle
Syntle

Reputation: 5174

According to your screenshot your command only has 2 arguments and Arrays start from 0 therefore, you should have the first argument as args[0] and the second argument as args[1].

You also need to change message.mentions.first() to message.mentions.users.first()

Upvotes: 1

Related Questions