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 Role from '../../models/Role' ; module . exports = class DeleteRoleCommand extends Command { constructor ( client ) { super ( client , { name : 'delallroles' , group : 'roles' , memberName : 'delallroles' , description : 'Remove all reaction roles from the message.' , examples : [ 'delallroles #welcome 580458877531979786' ] , aliases : [ 'delroles' , 'deleteallroles' , 'deleteroles' , 'deleteallreactions' , 'deletereactions' , 'delallreactions' , 'delreactions' , ] , userPermissions : [ 'ADMINISTRATOR' ] , clientPermissions : [ 'MANAGE_MESSAGES' ] , guildOnly : true , throttling : { usages : 2 , duration : 10 , } , args : [ { key : 'channel' , prompt : 'Channel where the message for the reactions is placed in.' , type : 'channel' , default : '' , } , { key : 'messageID' , prompt : 'Message that the reactions should be removed from.' , 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 . 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 affectedRows = await Role . deleteMessageRoles ( args . messageID ) ; if ( affectedRows === 0 ) { return message . reply ( 'no reaction roles match the given credentials.' ) ; } const channelMessage = await args . channel . messages . fetch ( args . messageID ) ; if ( channelMessage ) { const roles = RoleManager . get ( ) . getRoles ( message . guild . id , channelMessage . channel . id , args . messageID ) ; for ( const [ roleID ] of roles ) { const messageReaction = channelMessage . reactions . resolve ( roleID ) ; if ( messageReaction ) { await messageReaction . remove ( ) ; } } } RoleManager . get ( ) . removeMessage ( message . guild . id , args . channel . id , args . messageID ) ; return message . reply ( 'all reaction roles have been successfully removed from the message.' ) ; } } ;