mute someone discord js

Solutions on MaxInterview for mute someone discord js by the best coders in the world

showing results for - "mute someone discord js"
Sara
25 Jun 2017
1const Discord = require('discord.js');
2const client = new Discord.Client();
3const prefix = "!";
4const token = ""; // Fill in your token
5
6client.on("message", msg => {
7  msg.content.startsWith(prefix + "mute") {
8    
9    
10    // Variables
11    var muteRole = msg.guild.roles.find(role => role.name.toLowerCase().includes("muted"));
12    var muteChannel = msg.guild.channels.find(channel => channel.name.includes("modlogs"));
13    var muteUser = msg.mentions.members.first();
14    var muteReason = msg.content.slice(prefix.length + 27);
15    
16    
17    // Conditions
18    if (!msg.member.hasPermission("MANAGE_MESSAGES")) return msg.channel.send("You don't have the permissions");
19    if (!muteUser) return msg.channel.send("You have to mention a valid member");
20    if (!muteChannel) return msg.channel.send("There's no channel called modlogs");
21    if (!muteRole) return msg.channel.send("There's no role called muted");
22    if (!msg.guild.member(client.user.id).hasPermission("MANAGE_ROLES")) return msg.channel.send("I Don't have permissions");
23    if (!muteReason) muteReason = "No reason given";
24    
25    // Embed
26    var muteEmbed = new Discord.RichEmbed() 
27    .setTitle("Mute")
28    .addField("Muted user", muteUser)
29    .addField("Reason", muteReason)
30    .setFooter(`Muted by ${msg.author.tag}`)
31    .setTimestamp();
32    
33    //Mute
34    muteUser.addRole(muteRole);
35    msg.channel.send(`${muteUser} has been muted`);
36    muteChannel.send(muteEmbed);
37    
38  }
39})