import { Command , CommandoClient , CommandoMessage } from 'discord.js-commando' ; import { Message , TextChannel } from 'discord.js' ; import { PermissionsManager } from '../../managers/permission.manager' ; import { RoleManager } from '../../managers/role.manager' ; import Emoji from '../../structures/Emoji' ; import Role from '../../models/Role' ; interface Arguments { channel : TextChannel | null ; messageID : string ; emojiRaw : string ; } module . exports = class DeleteRoleCommand extends Command { constructor ( client ) { super ( client , { name : 'delrole' , group : 'roles' , memberName : 'delrole' , description : 'Remove the reaction role from the message.' , examples : [ 'delrole #welcome 580458877531979786 :truckersmp:' ] , aliases : [ 'deleterole' , 'deletereaction' , 'delreaction' ] , userPermissions : [ 'ADMINISTRATOR' ] , clientPermissions : [ 'MANAGE_MESSAGES' ] , guildOnly : true , throttling : { usages : 3 , duration : 10 , } , args : [ { key : 'channel' , prompt : 'Channel where the message for the reaction is placed in.' , type : 'channel' , default : '' , } , { key : 'messageID' , prompt : 'Message that the reaction should be removed from.' , type : 'string' , default : '' , } , { key : 'emojiRaw' , prompt : 'Emoticon that was used for the reaction role.' , type : 'string' , default : '' , } , ] , } ) ; } hasPermission ( message , ownerOverride ? ) { if ( PermissionsManager . isGuildManager ( message . member ) ) { return true ; } return super . hasPermission ( message , ownerOverride ) ; } async run ( message , args ) { if ( ! args . channel || ! args . messageID || ! args . emojiRaw || args . channel . type !== 'text' || args . channel . guild . id !== message . guild . id ) { return message . reply ( 'please, provide valid parameters! For more information, ' + `run command \`${ message . guild . commandPrefix }help ${ this . name }\`` ) ; } const emoji = new Emoji ( args . emojiRaw ) ; const affectedRows = await Role . deleteReactionRole ( args . messageID , emoji . id ) ; if ( affectedRows === 0 ) { return message . reply ( 'no reaction matches the given credentials.' ) ; } try { const channelMessage = await args . channel . messages . fetch ( args . messageID ) ; const messageReaction = channelMessage . reactions . resolve ( emoji . id ) ; if ( messageReaction ) { await messageReaction . remove ( ) ; } } catch ( err ) { } RoleManager . get ( ) . removeRole ( message . guild . id , args . channel . id , args . messageID , emoji . id ) ; return message . reply ( 'the reaction role has been successfully removed.' ) ; } } ;