'Discord.js v12 doesnt execute a command
my code is:
In my code the warn command gets executed, but the warns command gets not, any help?
I also added a feature that checks if the message is !warns, because if i execute !warns !warn gets executed idk. its rigged.
I dont know what to write more it says you need more detail, but thats the case idk what to write more here
const args = message.content.trim().split(/ +/g);
if(message.content === "warns") return message.channel.send("checked")
if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.reply(norights);
let wUser = message.guild.member(message.mentions.users.first())
if (!wUser) return message.reply("Couldn't find them yo");
if (wUser.hasPermission("MANAGE_MESSAGES")) return message.reply(noperms);
let reason = args.join(" ").slice(22);
if (!warns[wUser.id]) warns[wUser.id] = {
warns: 0
};
warns[wUser.id].warns++;
fs.writeFile("./warnings.json", JSON.stringify(warns), (err) => {
if (err) logchannel.send(errorembed)
console.log(err)
});
let warnEmbed = new Discord.MessageEmbed()
.setDescription("Warns")
.setAuthor(message.author.username)
.setColor("#fc6400")
.addField("Warned User", `<@${wUser.id}>`)
.addField("Warned In", message.channel)
.addField("Number of Warnings", warns[wUser.id].warns)
.addField("Reason", reason);
let warnchannel = client.channels.cache.get(logchannel)
if (!warnchannel) return message.reply("Couldn't find channel");
warnchannel.send(warnEmbed);
if (warns[wUser.id].warns == 2) {
let muterole = message.guild.roles.find(`name`, "muted");
if (!muterole) return message.reply("You should create that role dude.");
let mutetime = "120s";
await (wUser.addRole(muterole.id));
message.channel.send(`<@${wUser.id}> has been temporarily muted`);
setTimeout(function() {
wUser.removeRole(muterole.id)
message.reply(`<@${wUser.id}> has been unmuted.`)
}, ms(mutetime))
}
if (warns[wUser.id].warns == 3) {
message.guild.member(wUser).kick(reason);
message.reply(`<@${wUser.id}> has been kicked.`)
}
}
if (message.content.startsWith(prefix + "warns")) {
console.log("executed")
let wUser = message.mentions.users.first()
if (!warns[wUser.id]) warns[wUser.id] = {
warns: 0
};
const warnsembed = new Discord.MessageEmbed()
.setTitle("Warns")
.setColor("#00ff00")
.setDescription("")
.addField("Number of Warnings", warns[wUser.id].warns)
message.channel.send(warnsembed)
}```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
