Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new parameters to discord.Embed #1996

Merged
merged 13 commits into from
Apr 18, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ These changes are available on the `master` branch, but have not yet been releas

### Added

- Added new parameters (`author`, `footer`, `image`, `thumbnail`) to `discord.Embed`.
([#1996](https://github.com/Pycord-Development/pycord/pull/1996))
- Added new events `on_bridge_command`, `on_bridge_command_completion`, and
`on_bridge_command_error`.
([#1916](https://github.com/Pycord-Development/pycord/pull/1916))
Expand Down
73 changes: 73 additions & 0 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
__all__ = (
"Embed",
"EmbedField",
"EmbedAuthor",
"EmbedFooter",
)


Expand Down Expand Up @@ -103,6 +105,61 @@ class _EmbedAuthorProxy(Protocol):
proxy_icon_url: MaybeEmpty[str]


class EmbedAuthor(EmbedProxy):
"""Represents the author on the :class:`Embed` object.

.. versionadded:: 2.5

Attributes
----------
name: :class:`str`
The name of the author.
url: :class:`str`
The URL of the hyperlink created in the author's name.
icon_url: :class:`str`
The URL of the author icon image.
"""

def __init__(
self,
name: str,
url: MaybeEmpty[str] = EmptyEmbed,
icon_url: MaybeEmpty[str] = EmptyEmbed,
) -> None:
layer = {
k: v
for k, v in locals().items()
if k in {"name", "url", "icon_url"} and v is not EmptyEmbed
}
super().__init__(layer)


class EmbedFooter(EmbedProxy):
"""Represents the footer on the :class:`Embed` object.

.. versionadded:: 2.5

Attributes
----------
text: :class:`str`
The text inside the footer.
icon_url: :class:`str`
The URL of the footer icon image.
"""

def __init__(
self,
text: str,
icon_url: MaybeEmpty[str] = EmptyEmbed,
) -> None:
layer = {
k: v
for k, v in locals().items()
if k in {"text", "icon_url"} and v is not EmptyEmbed
}
super().__init__(layer)


class EmbedField:
"""Represents a field on the :class:`Embed` object.

Expand Down Expand Up @@ -246,6 +303,10 @@ def __init__(
description: MaybeEmpty[Any] = EmptyEmbed,
timestamp: datetime.datetime = None,
fields: list[EmbedField] | None = None,
author: MaybeEmpty[EmbedAuthor] = EmptyEmbed,
footer: MaybeEmpty[EmbedFooter] = EmptyEmbed,
image: MaybeEmpty[str] = EmptyEmbed,
thumbnail: MaybeEmpty[str] = EmptyEmbed,
):
self.colour = colour if colour is not EmptyEmbed else color
self.title = title
Expand All @@ -266,6 +327,18 @@ def __init__(
self.timestamp = timestamp
self._fields: list[EmbedField] = fields or []

if author is not EmptyEmbed:
self.set_author(**author.__dict__)

if footer is not EmptyEmbed:
self.set_footer(**footer.__dict__)

if image is not EmptyEmbed:
self.set_image(url=image)

if thumbnail is not EmptyEmbed:
self.set_thumbnail(url=thumbnail)

@classmethod
def from_dict(cls: type[E], data: Mapping[str, Any]) -> E:
"""Converts a :class:`dict` to a :class:`Embed` provided it is in the
Expand Down
12 changes: 12 additions & 0 deletions docs/api/data_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ Embed
.. autoclass:: EmbedField
:members:

.. attributetable:: EmbedAuthor

.. autoclass:: EmbedAuthor
:members:


.. attributetable:: EmbedFooter

.. autoclass:: EmbedFooter
:members:



Flags
-----
Expand Down