Skip to content

Commit

Permalink
fix: KeyError in EmbedMedia (#2109)
Browse files Browse the repository at this point in the history
* fix `KeyError`

* Typehints and `proxy_url`
  • Loading branch information
OmLanke authored Jun 10, 2023
1 parent 96355dd commit e5aafe4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,18 @@ class EmbedMedia: # Thumbnail, Image, Video

url: str
proxy_url: str | None
height: int
width: int
height: int | None
width: int | None

@classmethod
def from_dict(cls, data: dict[str, str | int]) -> EmbedMedia:
self = cls.__new__(cls)
self.url = str(data.get("url"))
self.proxy_url = str(data.get("proxy_url"))
self.height = int(data["height"])
self.width = int(data["width"])
self.proxy_url = (
str(proxy_url) if (proxy_url := data.get("proxy_url")) else None
)
self.height = int(height) if (height := data.get("height")) else None
self.width = int(width) if (width := data.get("width")) else None
return self

def __repr__(self) -> str:
Expand Down

0 comments on commit e5aafe4

Please sign in to comment.