Skip to content

Commit

Permalink
feat(MessageComponentInteraction): component getter (#5840)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
  • Loading branch information
4 people committed Jun 26, 2021
1 parent adecead commit 1439183
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/structures/MessageComponentInteraction.js
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions typings/index.d.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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<RawMessageComponent, RawActionRowComponent> | null;
public componentType: MessageComponentType;
public customID: string;
public deferred: boolean;
Expand Down

0 comments on commit 1439183

Please sign in to comment.