mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com>
34 lines
816 B
TypeScript
34 lines
816 B
TypeScript
import type { JSONEncodable } from '../util/jsonEncodable';
|
|
import type { APIBaseMessageComponent, APIMessageComponent, ComponentType } from 'discord-api-types/v9';
|
|
|
|
/**
|
|
* Represents a discord component
|
|
*/
|
|
export abstract class Component<
|
|
DataType extends Partial<APIBaseMessageComponent<ComponentType>> & {
|
|
type: ComponentType;
|
|
} = APIBaseMessageComponent<ComponentType>,
|
|
> implements JSONEncodable<APIMessageComponent>
|
|
{
|
|
/**
|
|
* The API data associated with this component
|
|
*/
|
|
protected readonly data: DataType;
|
|
|
|
/**
|
|
* Converts this component to an API-compatible JSON object
|
|
*/
|
|
public abstract toJSON(): APIMessageComponent;
|
|
|
|
public constructor(data: DataType) {
|
|
this.data = data;
|
|
}
|
|
|
|
/**
|
|
* The type of this component
|
|
*/
|
|
public get type(): DataType['type'] {
|
|
return this.data.type;
|
|
}
|
|
}
|