discord js tempmute command

Solutions on MaxInterview for discord js tempmute command by the best coders in the world

showing results for - "discord js tempmute command"
Vanessa
05 Apr 2019
1function tempmute(message, args, prefix, client) {
2    var muterolename = "muted"; //Put the name of the muted role
3
4    var muteRole = message.guild.roles.cache.find(r => r.name === muterolename); //Gets data of muted role
5
6    var muteUser = message.mentions.members.first(); //Gets role your trying to mute
7  
8	// Conditions
9	if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply(":no_entry_sign: You do not have permissions to **mute** that user :no_entry_sign:");
10	if (!muteUser) return message.reply("You have to mention a valid member.");
11	if (!muteChannel) return message.reply("There's no channel called " + logchannel);
12	if (!muteRole) return message.reply("There's no role called " + muterolename);
13	if (!message.guild.member(client.user.id).hasPermission("MANAGE_ROLES")) return message.reply("I Don't have permissions");
14
15	var prefixLeangth = prefix.length; //Gets lenth of prefix
16	var minutes = args[2]; //Time in minutes
17	var muteReason = message.content.slice(6 + prefixLeangth, prefixLeangth + message.content.length); //Gets reason if one is one
18	if (!muteReason) var muteReason = "No reason given"; //Make the reason "No reason given" if field is left empty"
19
20	// Embed
21	var muteEmbed = new Discord.MessageEmbed()
22	muteEmbed.setTitle("Mute")
23	muteEmbed.addField("Muted user", muteUser)
24	muteEmbed.addField("Reason", muteReason)
25	muteEmbed.addField("Minutes", minutes)
26	muteEmbed.setFooter(`Muted by ${message.author.tag}`)
27	muteEmbed.setTimestamp();
28	
29  	message.content.send(muteEmbed)
30
31	// You need to parse those arguments, I'll leave that to you.
32
33	// Mute the user
34	muteUser.roles.add(muteRole, `Muted by ${message.author.tag} for ${minutes} minutes. Reason: ${muteReason}`);
35
36	// Unmute them after x minutes
37	timeout(minutes, muteUser, muteRole, message)
38}
39
40function timeout(minutes, muteUser, mutedRole, message) {
41	setTimeout(() => {
42    muteUser.roles.remove(mutedRole, `Temporary mute expired.`);
43
44    var muteEmbed = new Discord.MessageEmbed()
45    muteEmbed.setTitle("Unmute")
46    muteEmbed.addField("Unmuted user", muteUser)
47    muteEmbed.addField("Reason", 'Time ran out.')
48    muteEmbed.setFooter(`Unmuted by me`)
49    muteEmbed.setTimestamp();
50    message.channel.send(muteEmbed)
51  }, minutes * 60000); // time in ms
52}