Skip to content

Conversation

@Jiralite
Copy link
Member

@Jiralite Jiralite commented Oct 25, 2025

Please describe the changes this PR makes and why it should be merged:

When transforming a component for file uploads:

/**
* Transforms component data to discord.js-compatible data
*
* @param {*} rawComponent The data to transform
* @param {APIInteractionDataResolved} resolved The resolved data for the interaction
* @returns {ModalData[]}
* @private
*/
transformComponent(rawComponent, resolved) {
if ('components' in rawComponent) {
return {
type: rawComponent.type,
id: rawComponent.id,
components: rawComponent.components.map(component => this.transformComponent(component, resolved)),
};
}
if ('component' in rawComponent) {
return {
type: rawComponent.type,
id: rawComponent.id,
component: this.transformComponent(rawComponent.component, resolved),
};
}
const data = {
type: rawComponent.type,
id: rawComponent.id,
};
// Text display components do not have custom ids.
if ('custom_id' in rawComponent) data.customId = rawComponent.custom_id;
if ('value' in rawComponent) data.value = rawComponent.value;
if (rawComponent.values) {
data.values = rawComponent.values;
if (resolved) {
const { members, users, channels, roles, attachments } = resolved;
const valueSet = new Set(rawComponent.values);
if (users) {
data.users = new Collection();
for (const [id, user] of Object.entries(users)) {
if (valueSet.has(id)) {
data.users.set(id, this.client.users._add(user));
}
}
}
if (channels) {
data.channels = new Collection();
for (const [id, apiChannel] of Object.entries(channels)) {
if (valueSet.has(id)) {
data.channels.set(id, this.client.channels._add(apiChannel, this.guild) ?? apiChannel);
}
}
}
if (members) {
data.members = new Collection();
for (const [id, member] of Object.entries(members)) {
if (valueSet.has(id)) {
const user = users?.[id];
data.members.set(id, this.guild?.members._add({ user, ...member }) ?? member);
}
}
}
if (roles) {
data.roles = new Collection();
for (const [id, role] of Object.entries(roles)) {
if (valueSet.has(id)) {
data.roles.set(id, this.guild?.roles._add(role) ?? role);
}
}
}
if (attachments) {
data.attachments = new Collection();
for (const [id, attachment] of Object.entries(attachments)) {
if (valueSet.has(id)) {
data.attachments.set(id, new (getAttachment())(attachment));
}
}
}
}
}
return data;
}

We set type, id, customId, values, and attachments. Other fields are simply wrong.

JSDoc properties are correct:

/**
* @typedef {Object} BaseModalData
* @property {ComponentType} type The component type of the component
* @property {number} id The id of the component
*/
/**
* @typedef {BaseModalData} SelectMenuModalData
* @property {string} customId The custom id of the component
* @property {string[]} values The values of the component
* @property {Collection<string, GuildMember|APIGuildMember>} [members] The resolved members
* @property {Collection<string, User|APIUser>} [users] The resolved users
* @property {Collection<string, Role|APIRole>} [roles] The resolved roles
* @property {Collection<string, BaseChannel|APIChannel>} [channels] The resolved channels
*/
/**
* @typedef {BaseModalData} FileUploadModalData
* @property {string} customId The custom id of the file upload
* @property {string[]} values The values of the file upload
* @property {Collection<string, Attachment>} [attachments] The resolved attachments
*/

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Oct 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
discord-js Ignored Ignored Preview Oct 25, 2025 10:51pm
discord-js-guide Ignored Ignored Preview Oct 25, 2025 10:51pm

@Jiralite Jiralite changed the title types(FileUploadModalData): Correct fields #11209 types(FileUploadModalData): Correct fields Oct 25, 2025
@Jiralite Jiralite added this to the discord.js 15.0.0 milestone Oct 25, 2025
@Jiralite Jiralite linked an issue Oct 25, 2025 that may be closed by this pull request
@github-project-automation github-project-automation bot moved this from Todo to Review Approved in discord.js Oct 25, 2025
@kodiakhq kodiakhq bot merged commit 56662eb into main Oct 25, 2025
27 checks passed
@kodiakhq kodiakhq bot deleted the fix/file-upload-fields-main branch October 25, 2025 22:57
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

FileUploadModalData: inaccessible properties

5 participants