Answer the question
In order to leave comments, you need to log in
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"
}
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 questionAsk a Question
731 491 924 answers to any question