11import { PermissionFlagsBits , TextChannel } from 'discord.js' ;
22import { ExtendedClient } from '@structures/Client.js' ;
3- import { Command , CommandContext } from '@structures/Command.js' ;
3+ import { Command , CommandContext , CommandCheckFlags } from '@structures/Command.js' ;
44import { Embeds } from '@utils/Embeds.js' ;
55import { Argument } from '@structures/Argument.js' ;
66
@@ -10,6 +10,7 @@ export default class PurgeCommand extends Command {
1010 name : 'purge' ,
1111 description : 'Purge and recreate a channel' ,
1212 requiredPermissions : [ PermissionFlagsBits . ManageChannels ] ,
13+ checkFlags : CommandCheckFlags . Author | CommandCheckFlags . Guild ,
1314 args : [
1415 new Argument ( {
1516 name : 'channel' ,
@@ -22,17 +23,11 @@ export default class PurgeCommand extends Command {
2223 }
2324
2425 public async execute ( client : ExtendedClient , context : CommandContext ) : Promise < void > {
25- const guild = context . interaction ?. guild ?? context . message ?. guild ;
26- const author = context . interaction ?. user ?? context . message ?. author ;
27-
28- if ( ! guild ) {
29- return await context . reply ( {
30- embeds : [ Embeds . error ( 'This command can only be used in a server.' ) ] ,
31- } ) ;
32- }
26+ const guild = context . guild ! ;
27+ const author = context . author ! ;
3328
3429 const originalChannel = context . args . channel
35- ? guild ? .channels . cache . get ( context . args . channel as string )
30+ ? guild . channels . cache . get ( context . args . channel as string )
3631 : ( context . interaction ?. channel ?? context . message ?. channel ) ;
3732
3833 if ( ! originalChannel || ! originalChannel . isTextBased ( ) ) {
@@ -56,10 +51,10 @@ export default class PurgeCommand extends Command {
5651 }
5752
5853 await newChannel . setPosition ( textChannel . position ) ;
59- await textChannel . delete ( `Purged by ${ author ? .tag } ` ) ;
54+ await textChannel . delete ( `Purged by ${ author . tag } ` ) ;
6055
6156 await newChannel . send ( {
62- embeds : [ Embeds . success ( `Channel purged by ${ author ? .tag } ` ) ] ,
57+ embeds : [ Embeds . success ( `Channel purged by ${ author . tag } ` ) ] ,
6358 } ) ;
6459 }
6560}
0 commit comments