From a10d2924deadc53b26acb50cff3cb1f9de984b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Wed, 26 Mar 2025 21:06:03 +0000 Subject: [PATCH 1/2] add bool dunder for checking if media proxy has content --- discord/embeds.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/discord/embeds.py b/discord/embeds.py index 7f84e410d..6bd057ac8 100644 --- a/discord/embeds.py +++ b/discord/embeds.py @@ -61,6 +61,12 @@ class EmbedMediaProxy(EmbedProxy): super().__init__(layer) self._flags = self.__dict__.pop('flags', 0) + def __bool__(self) -> bool: + # This is a nasty check to see if we only have the `_flags` attribute which is created regardless in init. + # Had we had any of the other items, like image/video data this would be >1 and therefor + # would not be "empty". + return len(self.__dict__) > 1 + @property def flags(self) -> AttachmentFlags: return AttachmentFlags._from_value(self._flags or 0) From 6250feeced7bb627c0bc91ab552a6d9e50a45d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Tue, 6 May 2025 12:27:16 +0100 Subject: [PATCH 2/2] add regression test for the fix --- tests/test_embed.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_embed.py b/tests/test_embed.py index 3efedd6a5..004f73e3b 100644 --- a/tests/test_embed.py +++ b/tests/test_embed.py @@ -267,3 +267,14 @@ def test_embed_colour_setter_failure(value): embed = discord.Embed() with pytest.raises(TypeError): embed.colour = value + +@pytest.mark.parametrize( + ('title', 'return_val'), + [ + ('test', True), + (None, False) + ] +) +def test_embed_truthiness(title: str, return_val: bool) -> None: + embed = discord.Embed(title=title) + assert bool(embed) is return_val