feat: Add file type filtering for modals & / commands (#5236)

* feat: Add file type filtering for modals & / commands

* Add fileTypes to ApplicationCommandOption

* update comments

---------

Co-authored-by: Awesome Stickz <38146668+AwesomeStickz@users.noreply.github.com>
This commit is contained in:
Fleny
2026-08-14 22:19:09 +05:30
committed by GitHub
co-authored by Awesome Stickz
parent 7629302c13
commit f20c2b7300
7 changed files with 95 additions and 0 deletions
+1
View File
@@ -368,6 +368,7 @@ export function createDesiredPropertiesObject<T extends RecursivePartial<Transfo
component: defaultValue,
values: defaultValue,
resolved: defaultValue,
fileTypes: defaultValue,
...desiredProperties.component,
},
forumTag: {
@@ -18,6 +18,7 @@ export function transformApplicationCommandOption(bot: Bot, payload: DiscordAppl
minLength: payload.min_length,
maxLength: payload.max_length,
options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)),
fileTypes: payload.file_types,
} as ApplicationCommandOption;
return bot.transformers.customizers.applicationCommandOption(bot, payload, applicationCommandOption);
@@ -493,6 +493,7 @@ function transformFileUploadComponent(bot: Bot, payload: Partial<DiscordFileUplo
if (props.minValues && _payload.min_values) fileUpload.minValues = _payload.min_values;
if (props.maxValues && _payload.max_values) fileUpload.maxValues = _payload.max_values;
if (props.required && _payload.required) fileUpload.required = _payload.required;
if (props.fileTypes && _payload.file_types) fileUpload.fileTypes = _payload.file_types;
}
return fileUpload;
+36
View File
@@ -279,6 +279,24 @@ export interface ApplicationCommandOption {
maxLength?: number;
/** if autocomplete interactions are enabled for this `String`, `Integer`, or `Number` type option */
autocomplete?: boolean;
/**
* The accepted file types for the file upload
*
* @remarks
* The supported values are `image`, `video`, `audio` or any dot prefixed extension (e.g. `.pdf`)
*
* Extensions are case-insensitive and are normalized to lowercase, so `.PDF` and `.pdf` are equivalent.
*
* Discord recommends using the provided file groups rather than listing extensions individually.
* If you do list extensions individually, include `.jpg` for image uploads and both `.mp4` and `.mov` for video uploads,
* as some mobile clients rely on those extensions.
*
* This feature only checks the file extension against the filename and does not inspect the file contents.
* You are still responsible for validating the actual contents of the file.
*
* Up to 10 file types.
*/
fileTypes?: string[];
}
export interface ApplicationCommandOptionChoice {
@@ -690,6 +708,24 @@ export interface Component {
default?: boolean;
/** Resolved entities from selected options */
resolved?: InteractionDataResolved;
/**
* The accepted file types for the file upload
*
* @remarks
* The supported values are `image`, `video`, `audio` or any dot prefixed extension (e.g. `.pdf`)
*
* Extensions are case-insensitive and are normalized to lowercase, so `.PDF` and `.pdf` are equivalent.
*
* Discord recommends using the provided file groups rather than listing extensions individually.
* If you do list extensions individually, include `.jpg` for image uploads and both `.mp4` and `.mov` for video uploads,
* as some mobile clients rely on those extensions.
*
* This feature only checks the file extension against the filename and does not inspect the file contents.
* You are still responsible for validating the actual contents of the file.
*
* Up to 10 file types.
*/
fileTypes?: string[];
}
export interface UnfurledMediaItem {
+18
View File
@@ -818,6 +818,24 @@ export interface DiscordFileUploadComponent extends DiscordBaseComponent {
* @default true
*/
required?: boolean;
/**
* The accepted file types for the file upload
*
* @remarks
* The supported values are `image`, `video`, `audio` or any dot prefixed extension (e.g. `.pdf`)
*
* Extensions are case-insensitive and are normalized to lowercase, so `.PDF` and `.pdf` are equivalent.
*
* Discord recommends using the provided file groups rather than listing extensions individually.
* If you do list extensions individually, include `.jpg` for image uploads and both `.mp4` and `.mov` for video uploads,
* as some mobile clients rely on those extensions.
*
* This feature only checks the file extension against the filename and does not inspect the file contents.
* You are still responsible for validating the actual contents of the file.
*
* Up to 10 file types.
*/
file_types?: string[];
}
/** https://docs.discord.com/developers/components/reference#file-upload-file-upload-interaction-response-structure */
@@ -456,6 +456,26 @@ export interface DiscordApplicationCommandOption {
* When {@link DiscordApplicationCommandOption.choices | choices} are provided, this may not be set to true
*/
autocomplete?: boolean;
/**
* The accepted file types for the file upload
*
* @remarks
* The supported values are `image`, `video`, `audio` or any dot prefixed extension (e.g. `.pdf`)
*
* Extensions are case-insensitive and are normalized to lowercase, so `.PDF` and `.pdf` are equivalent.
*
* Discord recommends using the provided file groups rather than listing extensions individually.
* If you do list extensions individually, include `.jpg` for image uploads and both `.mp4` and `.mov` for video uploads,
* as some mobile clients rely on those extensions.
*
* This feature only checks the file extension against the filename and does not inspect the file contents.
* You are still responsible for validating the actual contents of the file.
*
* Up to 10 file types.
*
* Only valid in options of type {@link ApplicationCommandOptionTypes.Attachment | Attachment}
*/
file_types?: string[];
}
/** https://docs.discord.com/developers/interactions/application-commands#application-command-object-application-command-option-type */
@@ -474,6 +474,24 @@ export interface FileUploadComponent extends BaseComponent {
* @default true
*/
required?: boolean;
/**
* The accepted file types for the file upload
*
* @remarks
* The supported values are `image`, `video`, `audio` or any dot prefixed extension (e.g. `.pdf`)
*
* Extensions are case-insensitive and are normalized to lowercase, so `.PDF` and `.pdf` are equivalent.
*
* Discord recommends using the provided file groups rather than listing extensions individually.
* If you do list extensions individually, include `.jpg` for image uploads and both `.mp4` and `.mov` for video uploads,
* as some mobile clients rely on those extensions.
*
* This feature only checks the file extension against the filename and does not inspect the file contents.
* You are still responsible for validating the actual contents of the file.
*
* Up to 10 file types.
*/
fileTypes?: string[];
}
/** https://docs.discord.com/developers/components/reference#radio-group-structure */