File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ const embed = new EmbedBuilder()
34
34
{
35
35
name : "/ping" ,
36
36
value : "Pings the bot" ,
37
+ } ,
38
+ {
39
+ name : "/clear" ,
40
+ value : "clears `n` number of messages" ,
37
41
}
38
42
)
39
43
. setFooter ( {
Original file line number Diff line number Diff line change
1
+ import { SlashCommandBuilder } from "discord.js" ;
2
+
3
+ const data = new SlashCommandBuilder ( )
4
+ . setName ( "clear" )
5
+ . setDescription ( "clears n number of messages" )
6
+ . addIntegerOption ( ( option ) =>
7
+ option
8
+ . setName ( "number" )
9
+ . setDescription ( "number of messages you want to delete" )
10
+ . setRequired ( true )
11
+ ) ;
12
+
13
+ const execute = async ( interaction : any ) => {
14
+ try {
15
+ const number = interaction . options . getInteger ( "number" ) ;
16
+
17
+ if ( number < 1 || number > 100 ) {
18
+ return await interaction . reply ( {
19
+ content : "Please provide a number between 1 and 100." ,
20
+ ephemeral : true ,
21
+ } ) ;
22
+ }
23
+
24
+ if ( ! interaction . member . permissions . has ( "MANAGE_MESSAGES" ) ) {
25
+ return await interaction . reply ( {
26
+ content : "You don't have permission to use this command." ,
27
+ ephemeral : true ,
28
+ } ) ;
29
+ }
30
+
31
+ const messages = await interaction . channel . messages . fetch ( {
32
+ limit : number + 1 ,
33
+ } ) ;
34
+
35
+ await interaction . channel . bulkDelete ( messages ) ;
36
+
37
+ await interaction . reply ( {
38
+ content : `Successfully deleted ${ number } messages.` ,
39
+ ephemeral : true ,
40
+ } ) ;
41
+ } catch ( e ) {
42
+ console . error ( e ) ;
43
+ }
44
+ } ;
45
+
46
+ export = {
47
+ data,
48
+ execute,
49
+ } ;
Original file line number Diff line number Diff line change 101
101
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
102
102
"skipLibCheck" : true /* Skip type checking all .d.ts files. */
103
103
},
104
- "include" : [" src" , " play/server.ts" , " play/user.ts" ]
104
+ "include" : [" src" , " play/server.ts" , " play/user.ts" ],
105
+ "exclude" : [" play" ]
105
106
}
You can’t perform that action at this time.
0 commit comments