Skip to content

Commit

Permalink
feat(Message): Add method to resolve a component by id (#6484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Aug 24, 2021
1 parent 9ca10cc commit 57b94b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/structures/Message.js
Expand Up @@ -817,6 +817,15 @@ class Message extends Base {
return this.edit({ attachments: [] });
}

/**
* Resolves a component by a custom id.
* @param {string} customId The custom id to resolve against
* @returns {?MessageActionRowComponent}
*/
resolveComponent(customId) {
return this.components.flatMap(row => row.components).find(component => component.customId === customId) ?? null;
}

/**
* Used mainly internally. Whether two messages are identical in properties. If you want to compare messages
* without checking all the properties, use `message.id === message2.id`, which is much more efficient. This
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -1169,6 +1169,7 @@ export class Message extends Base {
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
public removeAttachments(): Promise<Message>;
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
public resolveComponent(customId: string): MessageActionRowComponent | null;
public startThread(options: StartThreadOptions): Promise<ThreadChannel>;
public suppressEmbeds(suppress?: boolean): Promise<Message>;
public toJSON(): unknown;
Expand Down

0 comments on commit 57b94b9

Please sign in to comment.