mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(MessageComponentInteraction): component getter (#5840)
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>
This commit is contained in:
@@ -57,6 +57,19 @@ class MessageComponentInteraction extends Interaction {
|
|||||||
this.webhook = new InteractionWebhook(this.client, this.applicationID, this.token);
|
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
|
* Resolves the type of a MessageComponent
|
||||||
* @param {MessageComponentTypeResolvable} type The type to resolve
|
* @param {MessageComponentTypeResolvable} type The type to resolve
|
||||||
|
|||||||
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@@ -139,10 +139,12 @@ declare module 'discord.js' {
|
|||||||
import BaseCollection from '@discordjs/collection';
|
import BaseCollection from '@discordjs/collection';
|
||||||
import { ChildProcess } from 'child_process';
|
import { ChildProcess } from 'child_process';
|
||||||
import {
|
import {
|
||||||
|
APIActionRowComponent as RawActionRowComponent,
|
||||||
APIInteractionDataResolvedChannel as RawInteractionDataResolvedChannel,
|
APIInteractionDataResolvedChannel as RawInteractionDataResolvedChannel,
|
||||||
APIInteractionDataResolvedGuildMember as RawInteractionDataResolvedGuildMember,
|
APIInteractionDataResolvedGuildMember as RawInteractionDataResolvedGuildMember,
|
||||||
APIInteractionGuildMember as RawInteractionGuildMember,
|
APIInteractionGuildMember as RawInteractionGuildMember,
|
||||||
APIMessage as RawMessage,
|
APIMessage as RawMessage,
|
||||||
|
APIMessageComponent as RawMessageComponent,
|
||||||
APIOverwrite as RawOverwrite,
|
APIOverwrite as RawOverwrite,
|
||||||
APIPartialEmoji as RawEmoji,
|
APIPartialEmoji as RawEmoji,
|
||||||
APIRole as RawRole,
|
APIRole as RawRole,
|
||||||
@@ -1389,6 +1391,7 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class MessageComponentInteraction extends Interaction {
|
export class MessageComponentInteraction extends Interaction {
|
||||||
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | null;
|
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | null;
|
||||||
|
public readonly component: MessageActionRowComponent | Exclude<RawMessageComponent, RawActionRowComponent> | null;
|
||||||
public componentType: MessageComponentType;
|
public componentType: MessageComponentType;
|
||||||
public customID: string;
|
public customID: string;
|
||||||
public deferred: boolean;
|
public deferred: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user