diff --git a/src/structures/MessageComponentInteraction.js b/src/structures/MessageComponentInteraction.js index 7dece90b5221..62bc95aba183 100644 --- a/src/structures/MessageComponentInteraction.js +++ b/src/structures/MessageComponentInteraction.js @@ -57,6 +57,19 @@ class MessageComponentInteraction extends Interaction { this.webhook = new InteractionWebhook(this.client, this.applicationID, this.token); } + /** + * The component which was interacted with + * @type {?(MessageActionRowComponent|Object)} + * @readonly + */ + get component() { + return ( + this.message.components + .flatMap(row => row.components) + .find(component => (component.customID ?? component.custom_id) === this.customID) ?? null + ); + } + /** * Resolves the type of a MessageComponent * @param {MessageComponentTypeResolvable} type The type to resolve diff --git a/typings/index.d.ts b/typings/index.d.ts index 35d46edcc8b5..4eba6212221b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -139,10 +139,12 @@ declare module 'discord.js' { import BaseCollection from '@discordjs/collection'; import { ChildProcess } from 'child_process'; import { + APIActionRowComponent as RawActionRowComponent, APIInteractionDataResolvedChannel as RawInteractionDataResolvedChannel, APIInteractionDataResolvedGuildMember as RawInteractionDataResolvedGuildMember, APIInteractionGuildMember as RawInteractionGuildMember, APIMessage as RawMessage, + APIMessageComponent as RawMessageComponent, APIOverwrite as RawOverwrite, APIPartialEmoji as RawEmoji, APIRole as RawRole, @@ -1389,6 +1391,7 @@ declare module 'discord.js' { export class MessageComponentInteraction extends Interaction { public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | null; + public readonly component: MessageActionRowComponent | Exclude | null; public componentType: MessageComponentType; public customID: string; public deferred: boolean;