Files
discord.js/packages/structures/src/messages/components/UnfurledMediaItem.ts
Qjuh 19253f6b7b feat: message structures (#10982)
* feat: message structures

* fix: docs

* chore: components and more

* feat: embed and more

* feat: more substructures and code review suggestions

* chore: tests and date conversions

* chore: jsdoc strings

* fix: tests

* fix: tests

* feat: hexColor getters

* chore: remove getters for nested data

* chore: apply suggestions from code review

* fix: burst_colors in toJSON

* docs: rephrase SectionBuilder remark

* chore: add LabelComponent

* fix: add name and size to file component

* chore: move resolved interaction data to interactions dir

* fix: code review

* chore: bump discord-api-types

* chore: apply code review suggestions

* fix: lockfile

* chore: update remark

* fix: missing export

* chore: code review and tests

* build: fix file

* fix: typo

* fix: missing toJSON

* fix: remove redundant patch overrides

* chore: missing component suffix

* chore: better name

* chore: add comment explaining timestamp conversion

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
2025-11-28 16:52:42 +00:00

71 lines
1.7 KiB
TypeScript

import type { APIUnfurledMediaItem } from 'discord-api-types/v10';
import { Structure } from '../../Structure.js';
import { kData } from '../../utils/symbols.js';
import type { Partialize } from '../../utils/types.js';
// TODO: add `flags` as a BitField class and appropriate getter, once it gets properly documented
/**
* Represents a media item in a component on a message.
*
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
*/
export class UnfurledMediaItem<Omitted extends keyof APIUnfurledMediaItem | '' = ''> extends Structure<
APIUnfurledMediaItem,
Omitted
> {
/**
* The template used for removing data from the raw data stored for each UnfurledMediaItem.
*/
public static override readonly DataTemplate: Partial<APIUnfurledMediaItem> = {};
/**
* @param data - The raw data received from the API for the unfurled media item
*/
public constructor(data: Partialize<APIUnfurledMediaItem, Omitted>) {
super(data);
}
/**
* The id of the uploaded attachment
*/
public get attachmentId() {
return this[kData].attachment_id;
}
/**
* The media type of the content
*/
public get contentType() {
return this[kData].content_type;
}
/**
* The height of the media item (if image)
*/
public get height() {
return this[kData].height;
}
/**
* The proxied URL of the media item
*/
public get proxyURL() {
return this[kData].proxy_url;
}
/**
* Supports arbitrary URLs and attachment:// references
*/
public get url() {
return this[kData].url;
}
/**
* The width of the media item (if image)
*/
public get width() {
return this[kData].width;
}
}