Skip to content

renzbobz/DiscordEmbed-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

DiscordEmbed-PHP

Easily create an object for discord embed.

Major Released: 2/8/23

Getting started

Installation

Download the DiscordEmbed.php file and then require it to your project and you're ready to go!

require "DiscordEmbed.php";

Usage

Create new instance every time you create a new embed.

$embed = (new DiscordEmbed)
  ->setTitle("Cool title")
  ->setDescription("Cool description");

Methods

Title

setTitle(string $title, ?string $url);
prependTitle(string $title);
appendTitle(string $title);

Title Url

setUrl(string $url);

Description

setDescription(string $description);
prependDescription(string $description);
appendDescription(string $description);

Color

$color can be a hex, decimal, or rgb (comma separated).

setColor(int $color);
setColor(string $color);
setRandomColor();

Timestamp

setTimestamp(?string $ts = date('c'));

Author

# Associative array
$author = [
  "name" => string,
  "url" => ?string,
  "icon_url" => ?string,
  "proxy_icon_url" => ?string,
];
setAuthor(string $name, ?string $url, ?string $iconUrl, ?string $proxyIconUrl);
setAuthor(associative array $author);

Footer

# Associative array
$footer = [
  "text" => string,
  "icon_url" => string,
  "proxy_icon_url" => ?string,
];
setFooter(string $text, ?string $iconUrl, ?string $proxyIconUrl);
setFooter(associative array $footer);

Image

# Associative array
$image = [
  "url" => string,
  "proxy_url" => ?string,
  "height" => ?int,
  "width" => ?int,
];
setImage(string $url, ?string $proxyUrl, ?int $height, ?int $width);
setImage(associative array $image);

Thumbnail

$thumbnail = [
  # Associative array
  "url" => string,
  "proxy_url" => ?string,
  "height" => ?int,
  "width" => ?int,
];
setThumbnail(string $url, ?string $proxyUrl, ?int $height, ?int $width);
setThumbnail(associative array $thumbnail);

Add Field

# Associative array
$field = [
  "name" => string,
  "value" => ?string,
  "inline" => ?bool,
];
# Indexed array
$field = [
  string $name,
  ?string $value,
  ?bool $inline,
];
addField(associative array $field);
addField(string $name, ?string $value, ?bool $inline);
addFields(associative|indexed array ...$fields);

Formatting

toArray(): array;
toJSON(): string;