Skip to content

Commit e177b4a

Browse files
Fix EmbedMediaProxy boolean check
1 parent e84edf4 commit e177b4a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

discord/embeds.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def __init__(self, layer: Dict[str, Any]):
6161
super().__init__(layer)
6262
self._flags = self.__dict__.pop('flags', 0)
6363

64+
def __bool__(self) -> bool:
65+
# This is a nasty check to see if we only have the `_flags` attribute which is created regardless in init.
66+
# Had we had any of the other items, like image/video data this would be >1 and therefor
67+
# would not be "empty".
68+
return len(self.__dict__) > 1
69+
6470
@property
6571
def flags(self) -> AttachmentFlags:
6672
return AttachmentFlags._from_value(self._flags or 0)

tests/test_embed.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,14 @@ def test_embed_colour_setter_failure(value):
267267
embed = discord.Embed()
268268
with pytest.raises(TypeError):
269269
embed.colour = value
270+
271+
@pytest.mark.parametrize(
272+
('title', 'return_val'),
273+
[
274+
('test', True),
275+
(None, False)
276+
]
277+
)
278+
def test_embed_truthiness(title: str, return_val: bool) -> None:
279+
embed = discord.Embed(title=title)
280+
assert bool(embed) is return_val

0 commit comments

Comments
 (0)