1
- import { Interaction , Message , CommandInteraction , GuildMember , InteractionResponse , BooleanCache , EmbedBuilder , ChannelType , DiscordAPIError } from 'discord.js' ;
1
+ import { Interaction , Message , CommandInteraction , GuildMember , InteractionResponse , BooleanCache , EmbedBuilder , ChannelType , DiscordAPIError , AttachmentBuilder } from 'discord.js' ;
2
2
import { AsyncCommandStructure , CommandStructure } from '../structures' ;
3
3
import { IDiscordCommandContext } from '../../interfaces' ;
4
4
import { DiscordClient } from '../Client' ;
@@ -31,7 +31,7 @@ export class CommandListener {
31
31
member : message . member ,
32
32
author : message . author ,
33
33
messageReplyContent : null ,
34
- reply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < Message < boolean > > => {
34
+ reply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < Message < boolean > > => {
35
35
return new Promise ( async ( resolve , reject ) => {
36
36
message . reply ( this . replyParser ( ...content ) ) . then ( ( result ) => {
37
37
context . messageReplyContent = result ;
@@ -50,13 +50,13 @@ export class CommandListener {
50
50
} ) ;
51
51
} ) ;
52
52
} ,
53
- editReply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < Message > => {
53
+ editReply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < Message > => {
54
54
if ( context . messageReplyContent && ( context . messageReplyContent as Message < boolean > ) . editable ) {
55
55
return ( context . messageReplyContent as Message < boolean > ) . edit ( this . replyParser ( ...content ) ) ;
56
56
}
57
57
return ( context . reply ( ...content ) as Promise < Message < boolean > > ) ;
58
58
} ,
59
- discreteReply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < Message < boolean > > => {
59
+ discreteReply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < Message < boolean > > => {
60
60
return new Promise ( async ( resolve , reject ) => {
61
61
const parsedContent = this . replyParser ( ...content ) ;
62
62
message . reply ( {
@@ -68,6 +68,8 @@ export class CommandListener {
68
68
context . messageReplyContent = result ;
69
69
return resolve ( result ) ;
70
70
} ) . catch ( ( error : DiscordAPIError ) => {
71
+ // 10008: Unknown Message
72
+ // 50035: Cannot send messages to this user
71
73
if ( error . code === 10008 || error . code === 50035 ) {
72
74
message . channel . send ( this . replyParser ( ...content ) ) . then ( ( result ) => {
73
75
context . messageReplyContent = result ;
@@ -109,13 +111,13 @@ export class CommandListener {
109
111
member : ctx . member as GuildMember ,
110
112
author : ctx . user ,
111
113
args : ctx . options . data . map ( ( arg ) => arg . value ) ,
112
- reply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < InteractionResponse < boolean > > => {
114
+ reply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < InteractionResponse < boolean > > => {
113
115
return await ctx . reply ( this . replyParser ( ...content ) ) ;
114
116
} ,
115
- editReply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < Message < BooleanCache < any > > > => {
117
+ editReply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < Message < BooleanCache < any > > > => {
116
118
return await ctx . editReply ( this . replyParser ( ...content ) ) ;
117
119
} ,
118
- discreteReply : async ( ...content : [ string | EmbedBuilder ] ) : Promise < InteractionResponse < boolean > > => {
120
+ discreteReply : async ( ...content : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : Promise < InteractionResponse < boolean > > => {
119
121
return await ctx . reply ( { ...this . replyParser ( ...content ) , ephemeral : true } ) ;
120
122
} ,
121
123
deleteReply : async ( ) : Promise < void > => {
@@ -136,17 +138,22 @@ export class CommandListener {
136
138
}
137
139
}
138
140
139
- private replyParser ( ...params : [ string | EmbedBuilder ] ) : { content ?: string , embeds ?: EmbedBuilder [ ] } {
140
- const result : { content ?: string , embeds ?: EmbedBuilder [ ] } = {
141
+ private replyParser ( ...params : ( string | EmbedBuilder | AttachmentBuilder ) [ ] ) : { content ?: string , embeds ?: EmbedBuilder [ ] , files ?: AttachmentBuilder [ ] } {
142
+ const result : { content ?: string , embeds ?: EmbedBuilder [ ] , files ?: AttachmentBuilder [ ] } = {
141
143
content : '' ,
142
144
embeds : [ ] ,
145
+ files : [ ] ,
143
146
} ;
144
147
145
148
params . forEach ( ( item ) => {
146
149
if ( typeof item === 'string' ) {
147
- result . content = item ;
148
- } else {
150
+ result . content + = item ;
151
+ } else if ( item instanceof EmbedBuilder ) {
149
152
result . embeds ! . push ( item ) ;
153
+ } else if ( item instanceof AttachmentBuilder ) {
154
+ result . files ! . push ( item ) ;
155
+ } else {
156
+ throw new Error ( 'Invalid parameter type!' ) ;
150
157
}
151
158
} ) ;
152
159
0 commit comments