@@ -85,18 +85,18 @@ class CommandInteractionOptionResolver {
85
85
/**
86
86
* Gets an option by name and property and checks its type.
87
87
* @param {string } name The name of the option.
88
- * @param {ApplicationCommandOptionType } type The type of the option.
88
+ * @param {ApplicationCommandOptionType[] } allowedTypes The allowed types of the option.
89
89
* @param {string[] } properties The properties to check for for `required`.
90
90
* @param {boolean } required Whether to throw an error if the option is not found.
91
91
* @returns {?CommandInteractionOption } The option, if found.
92
92
* @private
93
93
*/
94
- _getTypedOption ( name , type , properties , required ) {
94
+ _getTypedOption ( name , allowedTypes , properties , required ) {
95
95
const option = this . get ( name , required ) ;
96
96
if ( ! option ) {
97
97
return null ;
98
- } else if ( option . type !== type ) {
99
- throw new DiscordjsTypeError ( ErrorCodes . CommandInteractionOptionType , name , option . type , type ) ;
98
+ } else if ( ! allowedTypes . includes ( option . type ) ) {
99
+ throw new DiscordjsTypeError ( ErrorCodes . CommandInteractionOptionType , name , option . type , allowedTypes . join ( ', ' ) ) ;
100
100
} else if ( required && properties . every ( prop => option [ prop ] === null || typeof option [ prop ] === 'undefined' ) ) {
101
101
throw new DiscordjsTypeError ( ErrorCodes . CommandInteractionOptionEmpty , name , option . type ) ;
102
102
}
@@ -134,7 +134,7 @@ class CommandInteractionOptionResolver {
134
134
* @returns {?boolean } The value of the option, or null if not set and not required.
135
135
*/
136
136
getBoolean ( name , required = false ) {
137
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Boolean , [ 'value' ] , required ) ;
137
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . Boolean ] , [ 'value' ] , required ) ;
138
138
return option ?. value ?? null ;
139
139
}
140
140
@@ -146,7 +146,7 @@ class CommandInteractionOptionResolver {
146
146
* The value of the option, or null if not set and not required.
147
147
*/
148
148
getChannel ( name , required = false ) {
149
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Channel , [ 'channel' ] , required ) ;
149
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . Channel ] , [ 'channel' ] , required ) ;
150
150
return option ?. channel ?? null ;
151
151
}
152
152
@@ -157,7 +157,7 @@ class CommandInteractionOptionResolver {
157
157
* @returns {?string } The value of the option, or null if not set and not required.
158
158
*/
159
159
getString ( name , required = false ) {
160
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . String , [ 'value' ] , required ) ;
160
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . String ] , [ 'value' ] , required ) ;
161
161
return option ?. value ?? null ;
162
162
}
163
163
@@ -168,7 +168,7 @@ class CommandInteractionOptionResolver {
168
168
* @returns {?number } The value of the option, or null if not set and not required.
169
169
*/
170
170
getInteger ( name , required = false ) {
171
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Integer , [ 'value' ] , required ) ;
171
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . Integer ] , [ 'value' ] , required ) ;
172
172
return option ?. value ?? null ;
173
173
}
174
174
@@ -179,7 +179,7 @@ class CommandInteractionOptionResolver {
179
179
* @returns {?number } The value of the option, or null if not set and not required.
180
180
*/
181
181
getNumber ( name , required = false ) {
182
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Number , [ 'value' ] , required ) ;
182
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . Number ] , [ 'value' ] , required ) ;
183
183
return option ?. value ?? null ;
184
184
}
185
185
@@ -190,7 +190,12 @@ class CommandInteractionOptionResolver {
190
190
* @returns {?User } The value of the option, or null if not set and not required.
191
191
*/
192
192
getUser ( name , required = false ) {
193
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . User , [ 'user' ] , required ) ;
193
+ const option = this . _getTypedOption (
194
+ name ,
195
+ [ ApplicationCommandOptionType . User , ApplicationCommandOptionType . Mentionable ] ,
196
+ [ 'user' ] ,
197
+ required ,
198
+ ) ;
194
199
return option ?. user ?? null ;
195
200
}
196
201
@@ -201,7 +206,12 @@ class CommandInteractionOptionResolver {
201
206
* The value of the option, or null if the user is not present in the guild or the option is not set.
202
207
*/
203
208
getMember ( name ) {
204
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . User , [ 'member' ] , false ) ;
209
+ const option = this . _getTypedOption (
210
+ name ,
211
+ [ ApplicationCommandOptionType . User , ApplicationCommandOptionType . Mentionable ] ,
212
+ [ 'member' ] ,
213
+ false ,
214
+ ) ;
205
215
return option ?. member ?? null ;
206
216
}
207
217
@@ -212,7 +222,12 @@ class CommandInteractionOptionResolver {
212
222
* @returns {?(Role|APIRole) } The value of the option, or null if not set and not required.
213
223
*/
214
224
getRole ( name , required = false ) {
215
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Role , [ 'role' ] , required ) ;
225
+ const option = this . _getTypedOption (
226
+ name ,
227
+ [ ApplicationCommandOptionType . Role , ApplicationCommandOptionType . Mentionable ] ,
228
+ [ 'role' ] ,
229
+ required ,
230
+ ) ;
216
231
return option ?. role ?? null ;
217
232
}
218
233
@@ -223,7 +238,7 @@ class CommandInteractionOptionResolver {
223
238
* @returns {?Attachment } The value of the option, or null if not set and not required.
224
239
*/
225
240
getAttachment ( name , required = false ) {
226
- const option = this . _getTypedOption ( name , ApplicationCommandOptionType . Attachment , [ 'attachment' ] , required ) ;
241
+ const option = this . _getTypedOption ( name , [ ApplicationCommandOptionType . Attachment ] , [ 'attachment' ] , required ) ;
227
242
return option ?. attachment ?? null ;
228
243
}
229
244
@@ -237,7 +252,7 @@ class CommandInteractionOptionResolver {
237
252
getMentionable ( name , required = false ) {
238
253
const option = this . _getTypedOption (
239
254
name ,
240
- ApplicationCommandOptionType . Mentionable ,
255
+ [ ApplicationCommandOptionType . Mentionable ] ,
241
256
[ 'user' , 'member' , 'role' ] ,
242
257
required ,
243
258
) ;
@@ -252,7 +267,7 @@ class CommandInteractionOptionResolver {
252
267
* The value of the option, or null if not set and not required.
253
268
*/
254
269
getMessage ( name , required = false ) {
255
- const option = this . _getTypedOption ( name , '_MESSAGE' , [ 'message' ] , required ) ;
270
+ const option = this . _getTypedOption ( name , [ '_MESSAGE' ] , [ 'message' ] , required ) ;
256
271
return option ?. message ?? null ;
257
272
}
258
273
0 commit comments