mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
fix: allowedMentions, container, media item toJSON() for components v2 (#10852)
* fix: allowedMentions for components v2 * refactor: passing allowed_mentions * Update packages/discord.js/src/structures/MessagePayload.js * fix: missing UnfurledMediaItem#toJSON() * fix: find interactive component in container * fix: recursive flatMap * fix: lint * refactor: top-level function * fix: jsdoc * fix: jsdoc
This commit is contained in:
@@ -248,7 +248,8 @@ class MessagePayload {
|
|||||||
components,
|
components,
|
||||||
username,
|
username,
|
||||||
avatar_url: avatarURL,
|
avatar_url: avatarURL,
|
||||||
allowed_mentions: content === undefined && message_reference === undefined ? undefined : allowedMentions,
|
allowed_mentions:
|
||||||
|
this.isMessage && this.target.author.id !== this.target.client.user.id ? undefined : allowedMentions,
|
||||||
flags,
|
flags,
|
||||||
message_reference,
|
message_reference,
|
||||||
attachments: this.options.attachments,
|
attachments: this.options.attachments,
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ class UnfurledMediaItem {
|
|||||||
get url() {
|
get url() {
|
||||||
return this.data.url;
|
return this.data.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API-compatible JSON for this media item
|
||||||
|
* @returns {APIUnfurledMediaItem}
|
||||||
|
*/
|
||||||
|
toJSON() {
|
||||||
|
return { ...this.data };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = UnfurledMediaItem;
|
module.exports = UnfurledMediaItem;
|
||||||
|
|||||||
@@ -214,25 +214,36 @@ function createComponentBuilder(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts all interactive components from the component tree
|
||||||
|
* @param {Component|APIMessageComponent} component The component to find all interactive components in
|
||||||
|
* @returns {Array<Component|APIMessageComponent>}
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
function extractInteractiveComponents(component) {
|
||||||
|
switch (component.type) {
|
||||||
|
case ComponentType.ActionRow:
|
||||||
|
return component.components;
|
||||||
|
case ComponentType.Section:
|
||||||
|
return [...component.components, component.accessory];
|
||||||
|
case ComponentType.Container:
|
||||||
|
return component.components.flatMap(extractInteractiveComponents);
|
||||||
|
default:
|
||||||
|
return [component];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a component by customId in nested components
|
* Finds a component by customId in nested components
|
||||||
* @param {Array<Component|APIMessageComponent>} components The components to search in
|
* @param {Array<Component|APIMessageComponent>} components The components to search in
|
||||||
* @param {string} customId The customId to search for
|
* @param {string} customId The customId to search for
|
||||||
* @returns {Component|APIMessageComponent}
|
* @returns {Component|APIMessageComponent}
|
||||||
|
* @ignore
|
||||||
*/
|
*/
|
||||||
function findComponentByCustomId(components, customId) {
|
function findComponentByCustomId(components, customId) {
|
||||||
return (
|
return (
|
||||||
components
|
components
|
||||||
.flatMap(component => {
|
.flatMap(extractInteractiveComponents)
|
||||||
switch (component.type) {
|
|
||||||
case ComponentType.ActionRow:
|
|
||||||
return component.components;
|
|
||||||
case ComponentType.Section:
|
|
||||||
return [...component.components, component.accessory];
|
|
||||||
default:
|
|
||||||
return [component];
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.find(component => (component.customId ?? component.custom_id) === customId) ?? null
|
.find(component => (component.customId ?? component.custom_id) === customId) ?? null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
7
packages/discord.js/typings/index.d.ts
vendored
7
packages/discord.js/typings/index.d.ts
vendored
@@ -7043,7 +7043,12 @@ export interface MessageEditAttachmentData {
|
|||||||
export interface MessageEditOptions extends Omit<BaseMessageOptions, 'content'> {
|
export interface MessageEditOptions extends Omit<BaseMessageOptions, 'content'> {
|
||||||
content?: string | null;
|
content?: string | null;
|
||||||
attachments?: readonly (Attachment | MessageEditAttachmentData)[];
|
attachments?: readonly (Attachment | MessageEditAttachmentData)[];
|
||||||
flags?: BitFieldResolvable<Extract<MessageFlagsString, 'SuppressEmbeds'>, MessageFlags.SuppressEmbeds> | undefined;
|
flags?:
|
||||||
|
| BitFieldResolvable<
|
||||||
|
Extract<MessageFlagsString, 'SuppressEmbeds' | 'IsComponentsV2'>,
|
||||||
|
MessageFlags.SuppressEmbeds | MessageFlags.IsComponentsV2
|
||||||
|
>
|
||||||
|
| undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageReactionResolvable = MessageReaction | Snowflake | string;
|
export type MessageReactionResolvable = MessageReaction | Snowflake | string;
|
||||||
|
|||||||
Reference in New Issue
Block a user