Skip to content

feat(flags): add new flags to Embed and update Attachment flags - #1283

Open
Snipy7374 wants to merge 10 commits into
DisnakeDev:masterfrom
Snipy7374:feat/flags
Open

feat(flags): add new flags to Embed and update Attachment flags#1283
Snipy7374 wants to merge 10 commits into
DisnakeDev:masterfrom
Snipy7374:feat/flags

Conversation

@Snipy7374

Copy link
Copy Markdown
Collaborator

Summary

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running pdm lint
    • I have type-checked the code by running pdm pyright
  • This PR fixes an issue
  • This PR adds something new (e.g. new method or parameters)
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

Snipy7374

This comment was marked as off-topic.

Comment thread disnake/flags.py
Comment thread disnake/flags.py
Comment thread disnake/embeds.py
Comment on lines +274 to +284
if self._thumbnail and (thumbnail_flags := self._thumbnail.get("flags")):
self._thumbnail["flags"] = EmbedMediaFlags._from_value(thumbnail_flags) # type: ignore

self._video = data.get("video")
self._provider = data.get("provider")
self._author = data.get("author")

self._image = data.get("image")
if self._image and (image_flags := self._image.get("flags")):
self._image["flags"] = EmbedMediaFlags._from_value(image_flags) # type: ignore

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how this is done but I don't see much alternatives

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than save it here, we could make the flags when we access the image or thumbnail, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also no longer seems to be respected in serialisation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also no longer seems to be respected in serialisation.

What do you mean? It's not consistent with the lib?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than save it here, we could make the flags when we access the image or thumbnail, no?

that was my idea as well. It's still a bit awkward, but a separate EmbedProxy subclass that special-cases flags should do, and doesn't result in weird consistency issues with from_dict and to_dict.

@Snipy7374 Snipy7374 added t: enhancement New feature t: api support Support of Discord API features s: waiting for api/docs Issue/PR is waiting for API support/documentation labels Jan 31, 2025
Comment thread disnake/embeds.py Outdated
Comment thread disnake/embeds.py Outdated
@Snipy7374
Snipy7374 requested review from Enegg and shiftinv and removed request for Enegg August 22, 2025 09:25
Comment thread disnake/embeds.py
@onerandomusername onerandomusername added this to the disnake v2.11 milestone Sep 7, 2025
Co-authored-by: Eneg <42005170+Enegg@users.noreply.github.com>
Signed-off-by: arielle <me@arielle.codes>
@onerandomusername onerandomusername removed the s: waiting for api/docs Issue/PR is waiting for API support/documentation label Sep 9, 2025
@shiftinv shiftinv removed this from the disnake v2.11 milestone Sep 10, 2025
@read-the-docs-community

read-the-docs-community Bot commented Sep 29, 2025

Copy link
Copy Markdown

Documentation build overview

📚 disnake | 🛠️ Build #33292325 | 📁 Comparing 19421ce against latest (57e1005)

  🔍 Preview build  

49 files changed · ± 49 modified

± Modified

@onerandomusername

Copy link
Copy Markdown
Member

@Snipy7374 would you please resolve conflicts and rebase?

@@ -0,0 +1 @@
Add :attr:`Embed.flags`, ``Embed.image.flags``, ``Embed.thumbnail.flags``, :class:`EmbedFlags`, :class:`EmbedMediaFlags` and update the :class:`AttachmentFlags`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is missing the unfurled media item flags, which were added later in the API docs PR.

Comment thread disnake/types/embed.py
inline: NotRequired[bool]


class EmbedThumbnail(TypedDict):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API docs got rid of the image/thumbnail structure split, it would make sense to just add a EmbedThumbnail = EmbedImage alias here instead of updating the structures individually

Comment thread disnake/embeds.py
Comment on lines +470 to 474
.. versionchanged:: |vnext|

Added the ``flags`` attribute.

If an attribute is not set, it will be :data:`None`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionchanged:: |vnext|
Added the ``flags`` attribute.
If an attribute is not set, it will be :data:`None`.
If an attribute is not set, it will be :data:`None`.
.. versionchanged:: |vnext|
Added the ``flags`` attribute.

Comment thread disnake/embeds.py
Comment on lines +528 to 532
.. versionchanged:: |vnext|

Added the ``flags`` attribute.

If an attribute is not set, it will be :data:`None`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionchanged:: |vnext|
Added the ``flags`` attribute.
If an attribute is not set, it will be :data:`None`.
If an attribute is not set, it will be :data:`None`.
.. versionchanged:: |vnext|
Added the ``flags`` attribute.

Comment thread disnake/flags.py

@flag_value
def is_clip(self):
""":class:`bool`: Returns ``True`` if the attachment is a clip.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""":class:`bool`: Returns ``True`` if the attachment is a clip.
""":class:`bool`: Returns ``True`` if the attachment is a clip from a stream.

Comment thread disnake/flags.py
return 1 << 3

@flag_value
def contains_explicit_media(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag seems to have been removed from the docs again

Comment thread disnake/flags.py
) -> None: ...

@flag_value
def contains_explicit_media(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, was removed from the docs

Comment thread disnake/flags.py

@flag_value
def is_animated(self):
""":class:`bool`: Returns ``True`` if the embed media is animated."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""":class:`bool`: Returns ``True`` if the embed media is animated."""
""":class:`bool`: Returns ``True`` if the embed image is animated."""

"media" is plural, at least in this context (apparently it can be singular when referring to mass media?). "embed medium" also sounds a bit weird, so "embed image" seems like a good compromise to me

Comment thread disnake/message.py
Comment on lines +324 to +332
clip_participants: List[:class:`User`]
If this attachment is a clip returns a list of users who were in the stream.

.. versionadded:: |vnext|

clip_created_at: Optional[:class:`datetime.datetime`]
If this attachment is a clip returns the creation timestamp.

.. versionadded:: |vnext|

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clip_participants: List[:class:`User`]
If this attachment is a clip returns a list of users who were in the stream.
.. versionadded:: |vnext|
clip_created_at: Optional[:class:`datetime.datetime`]
If this attachment is a clip returns the creation timestamp.
.. versionadded:: |vnext|
clip_participants: :class:`list`\[:class:`User`]
The list of users who were in the stream, if this attachment is a clip.
.. versionadded:: |vnext|
clip_created_at: :class:`datetime.datetime` | :data:`None`
The creation timestamp, if this attachment is a clip.
.. versionadded:: |vnext|

Comment thread disnake/message.py
Comment on lines +373 to +378
self.clip_participants: list[User] = [
User(state=state, data=d) for d in data.get("clip_participants", [])
]
self.clip_created_at: datetime.datetime | None = utils.parse_time(
data.get("clip_created_at")
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few more non-flags-related additions in the API docs PR - I'd say this PR should either only add the new flags, or everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t: api support Support of Discord API features t: enhancement New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Embed and new Attachment flags

4 participants