2022-09-18 11:57:22 +01:00
import { CommandInteraction , EmbedBuilder , GuildMember , PermissionsBitField , SlashCommandBuilder , TextChannel } from "discord.js" ;
import EmbedColours from "../constants/EmbedColours" ;
import SettingsHelper from "../helpers/SettingsHelper" ;
2022-04-24 14:46:37 +01:00
import { Command } from "../type/command" ;
export default class Unmute extends Command {
constructor ( ) {
super ( ) ;
2022-09-18 11:57:22 +01:00
super . CommandBuilder = new SlashCommandBuilder ( )
. setName ( "unmute" )
2023-07-07 12:28:06 +01:00
. setDescription ( "(DEPRECATED) Unmute a member in the server with an optional reason" )
2022-09-18 11:57:22 +01:00
. setDefaultMemberPermissions ( PermissionsBitField . Flags . ModerateMembers )
. addUserOption ( option = >
option
. setName ( 'target' )
. setDescription ( 'The user' )
. setRequired ( true ) )
. addStringOption ( option = >
option
. setName ( 'reason' )
. setDescription ( 'The reason' ) ) ;
2022-04-24 14:46:37 +01:00
}
2022-09-18 11:57:22 +01:00
public override async execute ( interaction : CommandInteraction ) {
if ( ! interaction . guild || ! interaction . guildId ) return ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
const targetUser = interaction . options . get ( 'target' ) ;
const reasonInput = interaction . options . get ( 'reason' ) ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
if ( ! targetUser || ! targetUser . user || ! targetUser . member ) {
await interaction . reply ( 'Fields are required.' ) ;
return ;
2022-04-24 14:46:37 +01:00
}
2022-09-18 11:57:22 +01:00
const targetMember = targetUser . member as GuildMember ;
const reason = reasonInput && reasonInput . value ? reasonInput . value . toString ( ) : "*none*" ;
const logEmbed = new EmbedBuilder ( )
. setColor ( EmbedColours . Ok )
. setTitle ( "Member Unmuted" )
. setDescription ( ` <@ ${ targetUser . user . id } > \` ${ targetUser . user . tag } \` ` )
2023-08-11 20:52:16 +01:00
. setThumbnail ( targetUser . user . avatarURL ( ) )
2022-09-18 11:57:22 +01:00
. addFields ( [
{
name : "Moderator" ,
value : ` <@ ${ interaction . user . id } > ` ,
} ,
{
name : "Reason" ,
value : reason ,
} ,
] ) ;
2023-08-18 21:07:19 +01:00
const mutedRoleName = await SettingsHelper . GetSetting ( 'role.muted' , interaction . guildId ) ;
if ( ! mutedRoleName ) {
await interaction . reply ( 'Unable to find configuration. Please contact the bot author.' ) ;
return ;
}
const mutedRole = interaction . guild . roles . cache . find ( role = > role . name == mutedRoleName ) ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
if ( ! mutedRole ) {
await interaction . reply ( 'Muted role not found.' ) ;
return ;
2022-04-24 14:46:37 +01:00
}
if ( ! targetMember . manageable ) {
2022-09-18 11:57:22 +01:00
await interaction . reply ( 'Insufficient permissions. Please contact a moderator.' ) ;
return ;
2022-04-24 14:46:37 +01:00
}
2022-09-18 11:57:22 +01:00
await targetMember . roles . remove ( mutedRole ) ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
const channelName = await SettingsHelper . GetSetting ( 'channels.logs.mod' , interaction . guildId ) ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
if ( ! channelName ) return ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
const channel = interaction . guild . channels . cache . find ( x = > x . name == channelName ) as TextChannel ;
2022-04-24 14:46:37 +01:00
2022-09-18 11:57:22 +01:00
if ( channel ) {
await channel . send ( { embeds : [ logEmbed ] } ) ;
}
2023-07-07 12:28:06 +01:00
await interaction . reply ( "Please note the mute and unmute commands have been deprecated and will be removed in a future update. Please use timeout instead" ) ;
2022-04-24 14:46:37 +01:00
}
}