hikari.embeds#
Application and entities that are used to describe message embeds on Discord.
Embed #
Embed(
*,
title: str | None = None,
description: str | None = None,
url: str | None = None,
color: Colorish | None = None,
colour: Colorish | None = None,
timestamp: datetime | None = None,
)
Represents an embed.
author property #
author: EmbedAuthor | None
Return the author to show in the embed.
Will be None if not set.
Note
Use hikari.embeds.Embed.set_author to update this value.
color property writable #
color: Color | None
Return the colour of the embed.
This will be None if not set.
description property writable #
description: str | None
Return the description of the embed.
This will be None if not set.
fields property #
fields: Sequence[EmbedField]
Return the sequence of fields in the embed.
Note
Use hikari.embeds.Embed.add_field to add a new field, hikari.embeds.Embed.edit_field to edit an existing field, or hikari.embeds.Embed.remove_field to remove a field.
footer property #
footer: EmbedFooter | None
Return the footer of the embed.
Will be None if not set.
image property #
image: EmbedImage | None
Return the image set in the embed.
Will be None if not set.
Note
Use hikari.embeds.Embed.set_image to update this value.
provider property #
provider: EmbedProvider | None
Return the provider to show in the embed.
Will be None if not set.
Note
This object cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event with a custom provider set.
thumbnail property #
thumbnail: EmbedImage | None
Return the thumbnail set in the embed.
Will be None if not set.
Note
Use hikari.embeds.Embed.set_thumbnail to update this value.
timestamp property writable #
timestamp: datetime | None
Return the timestamp of the embed.
This will be None if not set.
Warning
Setting a non-timezone-aware datetime will result in a warning being raised. This is done due to potential confusion caused by Discord requiring a UTC timestamp for this field. Any non-timezone aware timestamp is interpreted as using the system's current timezone instead. Thus, using datetime.datetime.utcnow will result in a potentially incorrect timezone being set.
To generate a timezone aware timestamp, use one of the following snippets:
# Use UTC.
>>> datetime.datetime.now(tz=datetime.timezone.utc)
datetime.datetime(2020, 6, 5, 18, 29, 56, 424744, tzinfo=datetime.timezone.utc)
# Use your current timezone.
>>> datetime.datetime.now().astimezone()
datetime.datetime(2020, 7, 7, 8, 57, 9, 775328, tzinfo=..., 'BST'))
By specifying a timezone, Hikari can automatically adjust the given time to UTC without you needing to think about it.
You can generate a timezone-aware timestamp instead of a timezone-naive one by specifying a timezone. Hikari will detect any difference in timezone if the timestamp is non timezone-naive and fix it for you:
# I am British, and it is June, so we are in daylight saving
# (UTC+1 or GMT+1, specifically).
>>> import datetime
# This is timezone naive, notice no timezone in the repr that
# gets printed. This is no good to us, as Discord will interpret it
# as being in the future!
>>> datetime.datetime.now()
datetime.datetime(2020, 6, 5, 19, 29, 48, 281716)
# Instead, this is a timezone-aware timestamp, and we can use this
# correctly. This will always return the current time in UTC.
>>> datetime.datetime.now(tz=datetime.timezone.utc)
datetime.datetime(2020, 6, 5, 18, 29, 56, 424744, tzinfo=datetime.timezone.utc)
# We could instead use a custom timezone. Since the timezone is
# explicitly specified, Hikari will convert it to UTC for you when
# you send the embed.
>>> ...
A library on PyPI called tzlocal also exists that may be useful to you if you need to get your local timezone for any reason:
>>> import datetime
>>> import tzlocal
# Naive datetime that will show the wrong time on Discord.
>>> datetime.datetime.now()
datetime.datetime(2020, 6, 5, 19, 33, 21, 329950)
# Timezone-aware datetime that uses my local timezone correctly.
>>> datetime.datetime.now(tz=tzlocal.get_localzone())
datetime.datetime(2020, 6, 5, 19, 33, 40, 967939, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
# Changing timezones.
>>> dt = datetime.datetime.now(tz=datetime.timezone.utc)
>>> print(dt)
datetime.datetime(2020, 6, 5, 18, 38, 27, 863990, tzinfo=datetime.timezone.utc)
>>> dt.astimezone(tzlocal.get_localzone())
datetime.datetime(2020, 6, 5, 19, 38, 27, 863990, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
...this is not required, but you may find it more useful if using the timestamps in debug logs, for example.
title property writable #
title: str | None
Return the title of the embed.
This will be None if not set.
url property writable #
url: str | None
Return the URL of the embed title.
This will be None if not set.
video property #
video: EmbedVideo | None
Return the video to show in the embed.
Will be None if not set.
Note
This object cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event with a video attached.
add_field #
Add a new field to this embed.
| PARAMETER | DESCRIPTION |
|---|---|
name | The field name. TYPE: |
value | The field value. TYPE: |
inline | If TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
clear_fields #
clear_fields() -> Embed
Remove all existing fields from this embed.
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
edit_field #
edit_field(
index: int,
name: UndefinedOr[str] = UNDEFINED,
value: UndefinedOr[str] = UNDEFINED,
/,
*,
inline: UndefinedOr[bool] = UNDEFINED,
) -> Embed
Edit an existing field on this embed.
| PARAMETER | DESCRIPTION |
|---|---|
index | The index of the field to edit. TYPE: |
name | The new field name to use. If left to the default ( TYPE: |
value | The new field value to use. If left to the default ( TYPE: |
inline |
TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
| RAISES | DESCRIPTION |
|---|---|
IndexError | Raised if the index is greater than |
from_received_embed classmethod #
from_received_embed(
*,
title: str | None,
description: str | None,
url: str | None,
color: Color | None,
timestamp: datetime | None,
image: EmbedImage | None,
thumbnail: EmbedImage | None,
video: EmbedVideo | None,
author: EmbedAuthor | None,
provider: EmbedProvider | None,
footer: EmbedFooter | None,
fields: MutableSequence[EmbedField] | None,
) -> Embed
Generate an embed from the given attributes.
Warning
This function is for internal use only!
remove_field #
Remove an existing field from this embed.
| PARAMETER | DESCRIPTION |
|---|---|
index | The index of the embed field to remove. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
| RAISES | DESCRIPTION |
|---|---|
IndexError | Raised if the index is greater than |
set_author #
set_author(
*,
name: str | None = None,
url: str | None = None,
icon: Resourceish | None = None,
) -> Embed
Set the author of this embed.
| PARAMETER | DESCRIPTION |
|---|---|
name | The optional name of the author. TYPE: |
url | The optional URL of the author. TYPE: |
icon | The optional image to show next to the embed author. This can be many different things, to aid in convenience.
TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
set_footer #
set_footer(
text: str | None, *, icon: Resourceish | None = None
) -> Embed
Set the footer of this embed.
| PARAMETER | DESCRIPTION |
|---|---|
text | The mandatory text string to set in the footer. If TYPE: |
icon | The optional image to show next to the embed footer. This can be many different things, to aid in convenience.
TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
set_image #
set_image(image: Resourceish | None = None) -> Embed
Set the image on this embed.
| PARAMETER | DESCRIPTION |
|---|---|
image | The optional resource to show for the embed image. This can be many different things, to aid in convenience.
TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
set_thumbnail #
set_thumbnail(image: Resourceish | None = None) -> Embed
Set the image on this embed.
| PARAMETER | DESCRIPTION |
|---|---|
image | The optional resource to show for the embed thumbnail. This can be many different things, to aid in convenience.
TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Embed | This embed. Allows for call chaining. |
EmbedAuthor #
EmbedField #
EmbedFooter #
Represents an embed footer.
icon class-attribute instance-attribute #
icon: EmbedResourceWithProxy | None = attrs.field(
default=None, repr=True
)
The URL of the footer icon, or None if not present.
EmbedImage #
Bases: EmbedResourceWithProxy
Represents an embed image.
height class-attribute instance-attribute #
The height of the image, if present and known, otherwise None.
Note
This field cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event.
EmbedProvider #
Represents an embed provider.
Note
This object cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event provided by an external source.
Therefore, you should never need to initialize an instance of this class yourself.
EmbedResource #
Bases: Resource[AsyncReader]
A base type for any resource provided in an embed.
Resources can be downloaded and uploaded.
resource class-attribute instance-attribute #
resource: Resource[AsyncReader] = attrs.field(repr=True)
The resource this object wraps around.
stream #
stream(
*,
executor: Executor | None = None,
head_only: bool = False,
) -> AsyncReaderContextManager[AsyncReader]
Produce a stream of data for the resource.
| PARAMETER | DESCRIPTION |
|---|---|
executor | The executor to run in for blocking operations. If TYPE: |
head_only | If TYPE: |
EmbedResourceWithProxy #
Bases: EmbedResource
Resource with a corresponding proxied element.
proxy_filename property #
proxy_filename: str | None
File name of the proxied version of this embed resource if applicable, else None.
proxy_resource class-attribute instance-attribute #
proxy_resource: Resource[AsyncReader] | None = attrs.field(
default=None, repr=False
)
The proxied version of the resource, or None if not present.
Note
This field cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event.
EmbedVideo #
Bases: EmbedResourceWithProxy
Represents an embed video.
Note
This object cannot be set by bots or webhooks while sending an embed and will be ignored during serialization. Expect this to be populated on any received embed attached to a message event with a video attached.
Therefore, you should never need to initialize an instance of this class yourself.