Embed
extends Part
in package
An embed object to be sent with a message.
Tags
Table of Contents
- TYPE_ARTICLE = 'article'
- TYPE_GIFV = 'gifv'
- TYPE_IMAGE = 'image'
- TYPE_LINK = 'link'
- TYPE_RICH = 'rich'
- TYPE_VIDEO = 'video'
- $author : Author|null
- $color : int|null
- $created : bool
- Is the part already created in the Discord servers?
- $description : string|null
- $fields : Collection|array<string|int, Field>
- $footer : Footer|null
- $image : Image|null
- $provider : object|null
- $scriptData : mixed
- Custom script data.
- $thumbnail : Image|null
- $timestamp : Carbon|null
- $title : string|null
- $type : string|null
- $url : string|null
- $video : Video|null
- $attributes : array<string|int, mixed>
- The parts attributes.
- $discord : Discord
- The Discord client.
- $factory : Factory
- The factory.
- $fillable : array<string|int, mixed>
- The parts fillable attributes.
- $hidden : array<string|int, mixed>
- Attributes that are hidden from debug info.
- $http : Http
- The HTTP client.
- $repositories : array<string|int, mixed>
- An array of repositories that can exist in a part.
- $repositories_cache : array<string|int, mixed>
- An array of repositories.
- $visible : array<string|int, mixed>
- Attributes which are visible from debug info.
- __construct() : mixed
- Create a new part instance.
- __debugInfo() : array<string|int, mixed>
- Handles debug calls from var_dump and similar functions.
- __get() : mixed
- Handles dynamic get calls onto the part.
- __serialize() : array<string|int, mixed>
- __set() : void
- Handles dynamic set calls onto the part.
- __toString() : string
- Converts the part to a string.
- __unserialize() : void
- addField() : $this
- Adds a field to the embed.
- addFieldValues() : $this
- Adds a field to the embed with values.
- ensureValidUrl() : void
- Ensures a url is valid for use in embeds.
- fetch() : ExtendedPromiseInterface<string|int, self>
- Fetches any missing information about the part from Discord's servers.
- fill() : void
- Fills the parts attributes from an array.
- getCreatableAttributes() : array<string|int, mixed>
- Returns the attributes needed to create.
- getPublicAttributes() : array<string|int, mixed>
- Returns an array of public attributes.
- getRawAttributes() : array<string|int, mixed>
- Returns an array of raw attributes.
- getRepositoryAttributes() : array<string|int, mixed>
- Gets the attributes to pass to repositories.
- getUpdatableAttributes() : array<string|int, mixed>
- Returns the updatable attributes.
- isPartial() : bool
- Whether the part is considered partial i.e. missing information which can be fetched from Discord.
- jsonSerialize() : array<string|int, mixed>
- Provides data when the part is encoded into JSON. Used for JsonSerializable.
- offsetExists() : bool
- Checks if an attribute exists via key. Used for ArrayAccess.
- offsetGet() : mixed
- Gets an attribute via key. Used for ArrayAccess.
- offsetSet() : void
- Sets an attribute via key. Used for ArrayAccess.
- offsetUnset() : void
- Unsets an attribute via key. Used for ArrayAccess.
- serialize() : string|null
- Serializes the data. Used for Serializable.
- setAuthor() : $this
- Set the author of this embed.
- setColor() : $this
- Sets the color of the embed.
- setDescription() : $this
- Sets the description of the embed.
- setFooter() : $this
- Set the footer of this embed.
- setImage() : $this
- Set the image of this embed.
- setThumbnail() : $this
- Set the thumbnail of this embed.
- setTimestamp() : $this
- Set the timestamp of this embed.
- setTitle() : $this
- Sets the title of the embed.
- setType() : $this
- Sets the type of the embed.
- setURL() : $this
- Set the URL of this embed.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- afterConstruct() : void
- Called after the part has been constructed.
- exceedsOverallLimit() : bool
- Checks to see if adding a property has put us over Discord's 6000 characters overall limit.
- getAuthorAttribute() : Author
- Gets the author attribute.
- getFieldsAttribute() : Collection|array<string|int, Field>
- Gets the fields attribute.
- getFooterAttribute() : Footer
- Gets the footer attribute.
- getImageAttribute() : Image
- Gets the image attribute.
- getThumbnailAttribute() : Image
- Gets the thumbnail attribute.
- getTimestampAttribute() : Carbon|null
- Gets the timestamp attribute.
- getVideoAttribute() : Video
- Gets the video attribute.
- resolveColor() : int
- Resolves a color to an integer.
- setColorAttribute() : mixed
- Sest the color of this embed.
- setDescriptionAttribute() : mixed
- Sets the description of this embed.
- setFieldsAttribute() : mixed
- Sets the fields attribute.
- setTitleAttribute() : $this
- Set the title of this embed.
- setTypeAttribute() : mixed
- Sets the type of the embed.
- attributeHelper() : mixed
- Helps with getting embed attributes.
- checkForMutator() : string|false
- Checks if there is a mutator present.
- getAttribute() : mixed
- Gets an attribute on the part.
- getEmbedTypes() : array<string|int, mixed>
- Returns all possible embed types.
- setAttribute() : void
- Sets an attribute on the part.
- studly() : string
- Converts a string to studlyCase.
Constants
TYPE_ARTICLE
public
mixed
TYPE_ARTICLE
= 'article'
TYPE_GIFV
public
mixed
TYPE_GIFV
= 'gifv'
TYPE_IMAGE
public
mixed
TYPE_IMAGE
= 'image'
TYPE_LINK
public
mixed
TYPE_LINK
= 'link'
TYPE_RICH
public
mixed
TYPE_RICH
= 'rich'
TYPE_VIDEO
public
mixed
TYPE_VIDEO
= 'video'
Properties
$author
public
Author|null
$author
The author of the embed.
$color
public
int|null
$color
The color of the embed.
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$description
public
string|null
$description
A description of the embed.
$fields
public
Collection|array<string|int, Field>
$fields
A collection of embed fields.
$footer
public
Footer|null
$footer
The footer of the embed.
$image
public
Image|null
$image
The image of the embed.
$provider read-only
public
object|null
$provider
The provider of the embed.
$scriptData
Custom script data.
public
mixed
$scriptData
Used for storing custom information, used by end products.
Tags
$thumbnail
public
Image|null
$thumbnail
The thumbnail of the embed.
$timestamp
public
Carbon|null
$timestamp
A timestamp of the embed.
$title
public
string|null
$title
The title of the embed.
$type read-only
public
string|null
$type
The type of the embed.
$url
public
string|null
$url
The URL of the embed.
$video read-only
public
Video|null
$video
The video of the embed.
$attributes
The parts attributes.
protected
array<string|int, mixed>
$attributes
= []
The parts attributes and content.
$discord
The Discord client.
protected
Discord
$discord
Client.
$factory
The factory.
protected
Factory
$factory
Factory.
$fillable
The parts fillable attributes.
protected
array<string|int, mixed>
$fillable
= ['title', 'type', 'description', 'url', 'timestamp', 'color', 'footer', 'image', 'thumbnail', 'video', 'provider', 'author', 'fields']
The array of attributes that can be mass-assigned.
$hidden
Attributes that are hidden from debug info.
protected
array<string|int, mixed>
$hidden
= []
Attributes that are hidden from public.
$http
The HTTP client.
protected
Http
$http
Client.
$repositories
An array of repositories that can exist in a part.
protected
array<string|int, mixed>
$repositories
= []
Repositories.
$repositories_cache
An array of repositories.
protected
array<string|int, mixed>
$repositories_cache
= []
$visible
Attributes which are visible from debug info.
protected
array<string|int, mixed>
$visible
= []
Methods
__construct()
Create a new part instance.
public
__construct(Discord $discord[, array<string|int, mixed> $attributes = [] ][, bool $created = false ]) : mixed
Parameters
- $discord : Discord
-
The Discord client.
- $attributes : array<string|int, mixed> = []
-
An array of attributes to build the part.
- $created : bool = false
-
Whether the part has already been created.
Return values
mixed —__debugInfo()
Handles debug calls from var_dump and similar functions.
public
__debugInfo() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
__get()
Handles dynamic get calls onto the part.
public
__get(string $key) : mixed
Parameters
- $key : string
-
The attributes key.
Tags
Return values
mixed —The value of the attribute.
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed> —__set()
Handles dynamic set calls onto the part.
public
__set(string $key, mixed $value) : void
Parameters
- $key : string
-
The attributes key.
- $value : mixed
-
The attributes value.
Tags
Return values
void —__toString()
Converts the part to a string.
public
__toString() : string
Tags
Return values
string —A JSON string of attributes.
__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —addField()
Adds a field to the embed.
public
addField(mixed ...$fields) : $this
Parameters
- $fields : mixed
Tags
Return values
$this —addFieldValues()
Adds a field to the embed with values.
public
addFieldValues(string $name, string $value[, bool $inline = false ]) : $this
Parameters
- $name : string
-
Maximum length is 256 characters.
- $value : string
-
Maximum length is 1024 characters.
- $inline : bool = false
-
Whether this field gets shown with other inline fields on one line.
Tags
Return values
$this —ensureValidUrl()
Ensures a url is valid for use in embeds.
public
ensureValidUrl([string|null $url = null ][, array<string|int, mixed> $allowed = ['http', 'https', 'attachment'] ]) : void
Parameters
- $url : string|null = null
- $allowed : array<string|int, mixed> = ['http', 'https', 'attachment']
Tags
Return values
void —fetch()
Fetches any missing information about the part from Discord's servers.
public
fetch() : ExtendedPromiseInterface<string|int, self>
Tags
Return values
ExtendedPromiseInterface<string|int, self> —fill()
Fills the parts attributes from an array.
public
fill(array<string|int, mixed> $attributes) : void
Parameters
- $attributes : array<string|int, mixed>
-
An array of attributes to build the part.
Return values
void —getCreatableAttributes()
Returns the attributes needed to create.
public
getCreatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getPublicAttributes()
Returns an array of public attributes.
public
getPublicAttributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
getRawAttributes()
Returns an array of raw attributes.
public
getRawAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —Raw attributes.
getRepositoryAttributes()
Gets the attributes to pass to repositories.
public
getRepositoryAttributes() : array<string|int, mixed>
Note: The order matters for repository tree (top to bottom).
Return values
array<string|int, mixed> —Attributes.
getUpdatableAttributes()
Returns the updatable attributes.
public
getUpdatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —isPartial()
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
public
isPartial() : bool
Return values
bool —jsonSerialize()
Provides data when the part is encoded into JSON. Used for JsonSerializable.
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
offsetExists()
Checks if an attribute exists via key. Used for ArrayAccess.
public
offsetExists(string $key) : bool
Parameters
- $key : string
-
The attribute key.
Return values
bool —Whether the offset exists.
offsetGet()
Gets an attribute via key. Used for ArrayAccess.
public
offsetGet(string $key) : mixed
Parameters
- $key : string
-
The attribute key.
Tags
Return values
mixed —offsetSet()
Sets an attribute via key. Used for ArrayAccess.
public
offsetSet(string $key, mixed $value) : void
Parameters
- $key : string
-
The attribute key.
- $value : mixed
-
The attribute value.
Tags
Return values
void —offsetUnset()
Unsets an attribute via key. Used for ArrayAccess.
public
offsetUnset(string $key) : void
Parameters
- $key : string
-
The attribute key.
Return values
void —serialize()
Serializes the data. Used for Serializable.
public
serialize() : string|null
Return values
string|null —A string of serialized data.
setAuthor()
Set the author of this embed.
public
setAuthor(string $name[, string|Attachment|null $iconurl = null ][, string|null $url = null ]) : $this
Parameters
- $name : string
-
Maximum length is 256 characters.
- $iconurl : string|Attachment|null = null
-
The URL to the icon, only http(s) and attachments URLs are allowed.
- $url : string|null = null
-
The URL to the author, only http(s) URLs are allowed.
Tags
Return values
$this —setColor()
Sets the color of the embed.
public
setColor(mixed $color) : $this
Parameters
- $color : mixed
Return values
$this —setDescription()
Sets the description of the embed.
public
setDescription(string $description) : $this
Parameters
- $description : string
Return values
$this —setFooter()
Set the footer of this embed.
public
setFooter(string $text[, string|Attachment|null $iconurl = null ]) : $this
Parameters
- $text : string
-
Maximum length is 2048 characters.
- $iconurl : string|Attachment|null = null
-
The URL to the icon, only http(s) and attachments URLs are allowed.
Tags
Return values
$this —setImage()
Set the image of this embed.
public
setImage(string|Attachment|null $url) : $this
Parameters
- $url : string|Attachment|null
-
The URL to the image, only http(s) and attachments URLs are allowed.
Tags
Return values
$this —setThumbnail()
Set the thumbnail of this embed.
public
setThumbnail(string|Attachment|null $url) : $this
Parameters
- $url : string|Attachment|null
-
The URL to the thumbnail, only http(s) and attachments URLs are allowed.
Tags
Return values
$this —setTimestamp()
Set the timestamp of this embed.
public
setTimestamp([int|null $timestamp = null ]) : $this
Parameters
- $timestamp : int|null = null
Tags
Return values
$this —setTitle()
Sets the title of the embed.
public
setTitle(string $title) : $this
Parameters
- $title : string
Return values
$this —setType()
Sets the type of the embed.
public
setType(string $type) : $this
Parameters
- $type : string
Tags
Return values
$this —setURL()
Set the URL of this embed.
public
setURL(string $url) : $this
Parameters
- $url : string
Return values
$this —unserialize()
Unserializes some data and stores it. Used for Serializable.
public
unserialize(string $data) : void
Parameters
- $data : string
-
Some serialized data.
Tags
Return values
void —afterConstruct()
Called after the part has been constructed.
protected
afterConstruct() : void
Return values
void —exceedsOverallLimit()
Checks to see if adding a property has put us over Discord's 6000 characters overall limit.
protected
exceedsOverallLimit(int $addition) : bool
Parameters
- $addition : int
Return values
bool —getAuthorAttribute()
Gets the author attribute.
protected
getAuthorAttribute() : Author
Return values
Author —The author attribute.
getFieldsAttribute()
Gets the fields attribute.
protected
getFieldsAttribute() : Collection|array<string|int, Field>
Return values
Collection|array<string|int, Field> —getFooterAttribute()
Gets the footer attribute.
protected
getFooterAttribute() : Footer
Return values
Footer —The footer attribute.
getImageAttribute()
Gets the image attribute.
protected
getImageAttribute() : Image
Return values
Image —The image attribute.
getThumbnailAttribute()
Gets the thumbnail attribute.
protected
getThumbnailAttribute() : Image
Return values
Image —The thumbnail attribute.
getTimestampAttribute()
Gets the timestamp attribute.
protected
getTimestampAttribute() : Carbon|null
Tags
Return values
Carbon|null —The timestamp attribute.
getVideoAttribute()
Gets the video attribute.
protected
getVideoAttribute() : Video
Return values
Video —The video attribute.
resolveColor()
Resolves a color to an integer.
protected
static resolveColor(array<string|int, mixed>|int|string $color) : int
Parameters
- $color : array<string|int, mixed>|int|string
Tags
Return values
int —setColorAttribute()
Sest the color of this embed.
protected
setColorAttribute(mixed $color) : mixed
Parameters
- $color : mixed
Tags
Return values
mixed —setDescriptionAttribute()
Sets the description of this embed.
protected
setDescriptionAttribute(string $description) : mixed
Parameters
- $description : string
-
Maximum length is 4096 characters.
Tags
Return values
mixed —setFieldsAttribute()
Sets the fields attribute.
protected
setFieldsAttribute(array<string|int, Field> $fields) : mixed
Parameters
- $fields : array<string|int, Field>
Return values
mixed —setTitleAttribute()
Set the title of this embed.
protected
setTitleAttribute(string $title) : $this
Parameters
- $title : string
-
Maximum length is 256 characters.
Tags
Return values
$this —setTypeAttribute()
Sets the type of the embed.
protected
setTypeAttribute(string $type) : mixed
Parameters
- $type : string
Tags
Return values
mixed —attributeHelper()
Helps with getting embed attributes.
private
attributeHelper(string $key, string $class) : mixed
Parameters
- $key : string
-
The attribute key.
- $class : string
-
The attribute class.
Tags
Return values
mixed —checkForMutator()
Checks if there is a mutator present.
private
checkForMutator(string $key, string $type) : string|false
Parameters
- $key : string
-
The attribute name to check.
- $type : string
-
Either get or set.
Return values
string|false —Either a string if it is callable or false.
getAttribute()
Gets an attribute on the part.
private
getAttribute(string $key) : mixed
Parameters
- $key : string
-
The key to the attribute.
Tags
Return values
mixed —Either the attribute if it exists or void.
getEmbedTypes()
Returns all possible embed types.
private
static getEmbedTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —setAttribute()
Sets an attribute on the part.
private
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
-
The key to the attribute.
- $value : mixed
-
The value of the attribute.
Return values
void —studly()
Converts a string to studlyCase.
private
static studly(string $string) : string
This is a port of updated Laravel's implementation, a non-regex with static cache. The Discord\studly() is kept due to unintended bug and we do not want to introduce BC by replacing it. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
-
The string to convert.