2020-01-25 10:02:43 +00:00
exports . run = async ( client , message , [ args , ... reason ] , level ) => {
const settings = message . settings ;
if ( ! args ) {
return message . channel . send ( "<:error:466995152976871434> Who am I meant to mute?" )
}
let user = message . mentions . members . first ( ) ;
let users ;
if ( ! user ) {
users = client . searchForMembers ( message . guild , args ) ;
if ( users . length > 1 )
return message . channel . send (
"<:error:466995152976871434> Found multiple users! Please be more specific or mention the user instead."
) ;
else if ( users . length == 0 )
return message . channel . send (
"<:error:466995152976871434> That user doesn't seem to exist. Try again!"
) ;
user = users [ 0 ] ;
} ;
if ( user . user . id === message . guild . ownerID ) {
return message . channel . send ( "<:error:466995152976871434> You can't mute the owner!" )
} ;
let moderator = message . guild . member ( message . author )
2020-03-09 01:11:33 +00:00
if ( message . settings . mutedRole . position >= moderator . roles . highest . position && level < 2 ) {
2020-01-25 10:02:43 +00:00
return message . channel . send (
"<:error:466995152976871434> The muted role is positioned above the moderator role! Please move the muted role below the moderator role."
) ;
} ;
2020-03-09 01:11:33 +00:00
if ( user . roles . highest . position >= moderator . roles . highest . position && moderator . user . id !== message . guild . ownerID ) {
2020-01-25 10:02:43 +00:00
return message . channel . send (
` <:error:466995152976871434> You can't mute people who have a higher role than you! `
) ;
} ;
let bot = message . guild . member ( client . user )
2020-03-09 01:11:33 +00:00
if ( user . roles . highest . position >= bot . roles . highest . position ) {
2020-01-25 10:02:43 +00:00
return message . channel . send (
` <:error:466995152976871434> I can't mute people who have a higher role than me! `
) ;
}
2020-03-09 01:11:33 +00:00
var role = message . guild . roles . cache . get ( settings . mutedRole ) ;
2020-01-25 10:02:43 +00:00
2020-03-09 01:11:33 +00:00
if ( ! role ) {
return message . channel . send (
"<:error:466995152976871434> There is no muted role set for this server. Please set one using `" + message . settings . prefix + "mutedrole <role>` before using this command."
) ;
2020-01-25 10:02:43 +00:00
} ;
2020-03-09 01:11:33 +00:00
if ( bot . roles . highest . position <= role . position ) {
2020-01-25 10:02:43 +00:00
return message . channel . send (
"<:error:466995152976871434> The muted role is above my highest role! Please move the muted role below my highest role."
) ;
} ;
2020-03-09 01:11:33 +00:00
message . guild . channels . cache . forEach ( async ( channel , id ) => {
await channel . updateOverwrite ( role , {
2020-01-25 10:02:43 +00:00
SEND _MESSAGES : false ,
ADD _REACTIONS : false
} ) ;
} ) ;
2020-03-09 01:11:33 +00:00
if ( user . roles . cache . has ( role . id ) ) {
2020-01-25 10:02:43 +00:00
return message . channel . send ( "<:error:466995152976871434> They're already muted!" )
}
2020-03-09 01:11:33 +00:00
await user . roles . add ( role . id ) ;
2020-01-25 10:02:43 +00:00
message . channel . send ( ` <:success:466995111885144095> Muted \` ${ user . user . tag } \` ` )
var muteReason = reason . join ( " " ) ;
if ( muteReason . length == 0 ) {
muteReason = "**No reason provided.**"
}
if ( settings . modlogsChannel !== "off" ) {
2020-03-09 01:11:33 +00:00
const channel = message . guild . channels . cache . find (
2020-01-25 10:02:43 +00:00
channel => channel . name === settings . modlogsChannel
) ;
if ( channel ) {
2020-03-09 01:11:33 +00:00
let embed = new Discord . MessageEmbed ( ) ;
2020-01-25 10:02:43 +00:00
embed . setColor ( "#a652bb" ) ;
2020-03-16 01:21:19 +00:00
embed . setAuthor ( "User muted!" , user . user . avatarURL ( { format : "png" , dynamic : true , size : 2048 } ) ) ;
2020-01-25 10:02:43 +00:00
embed . setDescription (
2020-03-09 01:11:33 +00:00
` • User: ${ user } ( ${ user . user . id } ) \n • Mod: ${ message . author } ( ${ message . author . id } ) \n • Reason: ${ muteReason } `
2020-01-25 10:02:43 +00:00
) ;
try {
2020-03-09 01:11:33 +00:00
channel . send ( embed ) ;
2020-01-25 10:02:43 +00:00
} catch ( err ) {
// probably no permissions to send messages/embeds there
}
}
}
} ;
exports . conf = {
enabled : true ,
guildOnly : true ,
2020-03-09 01:11:33 +00:00
aliases : [ ] ,
2020-01-25 10:02:43 +00:00
permLevel : "Moderator" ,
requiredPerms : [ "MANAGE_ROLES" , "MANAGE_CHANNELS" ]
} ;
exports . help = {
name : "mute" ,
category : "Moderation" ,
description : "Prevents the specified user from typing." ,
usage : "mute [member] <reason>"
} ;