DiscordPHP Documentation

UnfurledMediaItem
in package
implements JsonSerializable

Represents an unfurled media item, which is the base for V2 components.

It allows you to specify an arbitrary url or attachment reference.

Tags
link
https://discord.com/developers/docs/interactions/message-components#unfurled-media-items
since
10.5.0

Table of Contents

Interfaces

JsonSerializable

Constants

LOADING_STATE_LOADED_NOT_FOUND  = 3
LOADING_STATE_LOADED_SUCCESS  = 2
LOADING_STATE_LOADING  = 1
LOADING_STATE_UNKNOWN  = 0
Loading states for unfurled media items.

Properties

$content_type  : string|null
The media item's media type.
$height  : int|null
Height of media item.
$loading_state  : int|null
Loading state of the media item.
$proxy_url  : string|null
A proxied URL of the media item.
$url  : string
Source URL of media item (only supports http(s) and attachments).
$width  : int|null
Width of media item.

Methods

fromAttachment()  : self
Creates a new unfurled media item from an attachment.
getUrl()  : string
Returns the URL of the media item.
isLoaded()  : bool
Returns whether the media item was successfully loaded.
isLoading()  : bool
Returns whether the media item is still loading.
isNotFound()  : bool
Returns whether the media item failed to load.
isResolved()  : bool
Returns whether the media item has been resolved.
isUnknown()  : bool
Returns whether the media item's loading state is unknown.
jsonSerialize()  : array<string|int, mixed>
{@inheritDoc}
new()  : self
Creates a new unfurled media item.
setResolvedData()  : $this
Sets the resolved data for the media item.
setUrl()  : $this
Sets the URL of the media item.

Constants

LOADING_STATE_LOADED_NOT_FOUND

public mixed LOADING_STATE_LOADED_NOT_FOUND = 3

LOADING_STATE_UNKNOWN

Loading states for unfurled media items.

public mixed LOADING_STATE_UNKNOWN = 0

Properties

$content_type

The media item's media type.

private string|null $content_type

$loading_state

Loading state of the media item.

private int|null $loading_state

$url

Source URL of media item (only supports http(s) and attachments).

private string $url

Methods

fromAttachment()

Creates a new unfurled media item from an attachment.

public static fromAttachment(Attachment|string $filename) : self
Parameters
$filename : Attachment|string

Name of the attachment file, or null.

Return values
self

getUrl()

Returns the URL of the media item.

public getUrl() : string
Return values
string

isLoaded()

Returns whether the media item was successfully loaded.

public isLoaded() : bool
Return values
bool

isLoading()

Returns whether the media item is still loading.

public isLoading() : bool
Return values
bool

isNotFound()

Returns whether the media item failed to load.

public isNotFound() : bool
Return values
bool

isResolved()

Returns whether the media item has been resolved.

public isResolved() : bool
Return values
bool

isUnknown()

Returns whether the media item's loading state is unknown.

public isUnknown() : bool
Return values
bool

jsonSerialize()

{@inheritDoc}

public jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

new()

Creates a new unfurled media item.

public static new(string $url) : self
Parameters
$url : string

URL or attachment reference of the media item.

Return values
self

setResolvedData()

Sets the resolved data for the media item.

public setResolvedData(array<string|int, mixed> $data) : $this

This is typically set by Discord after the media is resolved.

Parameters
$data : array<string|int, mixed>

Resolved data from Discord.

Return values
$this

setUrl()

Sets the URL of the media item.

public setUrl(string $url) : $this
Parameters
$url : string

URL or attachment reference of the media item.

Return values
$this

        
On this page

Search results