feat(Message): Add method to resolve a component by id (#6484)

This commit is contained in:
Jiralite
2021-08-24 21:20:43 +01:00
committed by GitHub
parent 9ca10cce06
commit 57b94b9adf
2 changed files with 10 additions and 0 deletions

View File

@@ -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

1
typings/index.d.ts vendored
View File

@@ -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;