V
V
Vivitka2021-04-27 20:45:09
Node.js
Vivitka, 2021-04-27 20:45:09

How to create a warn command?

I want to create my own bot on my server (only on my server) and combine many functions in it .. So, I decided to do administration and wrote the following code for the warn command

const Discord = module.require("discord.js");
const fs = require("fs");
let profile = require("../profile.json")
module.exports.run = async (client,message,args) => {
    try{
    function send(msg){
        message.channel.send(msg);
    }

    if(!message.member.hasPermissions("KICK_MEMBERS")) return message.channel.send("Не хвататет прав.");
    let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));

    if(!args[0]) return send("Вы не указали пользователя.")
    if(!rUser) return send("Пользователь не найден.");
    profile[rUser.id].warns++;
    fs.writeFile('./profile.json',JSON.stringify(profile),(err=>{
        if(err) console.log(err);
    }));
    if(profile[rUser.id],warns >=3){
        message.guild.member(rUser).kick("3/3 Предупреждений.");
    }
    let embed = new Discord.MessageEmbed()
    .setDescription("Предупреждение.")
    .addField("Администратор",message.author.username)
    .addField("Выдал предупреждение",`${rUser.user.username}`)
    .addField("Количество предупреждений",`${profile[rUser.id].warns}/3`);
    
    message.channel.send(embed);
    }catch(err) {
        console.log(`1.${err.name}\n2.${err.message}\n3.${err.stack}`);
    }
};

module.exports.help = {
    name: "warn"
}


I tried it this way, though not much differently. And so, by the way, the command worked, but only without specifying the user.
client.on("message", async (message) => {
  if (message.content.startsWith(">warn")) {
    let victim = message.mentions.users.first();
    if (!victim) return message.reply("укажите пользователя!");
   let embed = new Discord.MessageEmbed()
    .setTitle("Предупреждение")
    .setDescription(`${victim} предупредил ${message.author}!`)
    .setColor("GREEN")
    .setFooter(`Администратор : ${message.author.username}`)
    .setTimestamp();

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

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question