Skip to content

Commit

Permalink
Fix end_time and http.edit_scheduled_event
Browse files Browse the repository at this point in the history
  • Loading branch information
Middledot committed Jan 19, 2022
1 parent 484922b commit 435c30d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ def edit_scheduled_event(self, guild_id: Snowflake, event_id: Snowflake, reason:
'entity_type',
'status',
'entity_metadata',
'image',
)
payload = {k: v for k, v in payload.items() if k in valid_keys}

Expand Down
22 changes: 18 additions & 4 deletions discord/scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class ScheduledEvent(Hashable):
Attributes
----------
guild: :class:`Guild`
The guild where the scheduled event is happening.
name: :class:`str`
The name of the scheduled event.
description: Optional[:class:`str`]
Expand Down Expand Up @@ -161,8 +163,8 @@ class ScheduledEvent(Hashable):
so there is no need to use this attribute.
created_at: :class:`datetime.datetime`
The datetime object of when the event was created.
guild: :class:`Guild`
The guild where the scheduled event is happening.
cover: Optional[:class:`Asset`]
The cover image of the scheduled event.
"""

__slots__ = (
Expand All @@ -177,6 +179,7 @@ class ScheduledEvent(Hashable):
'location',
'guild',
'_state',
'_cover',
'subscriber_count',
)

Expand Down Expand Up @@ -246,14 +249,15 @@ def cover(self) -> Optional[Asset]:
async def edit(
self,
*,
reason: Optional[str] = None,
name: str = MISSING,
description: str = MISSING,
status: Union[int, ScheduledEventStatus] = MISSING,
location: Union[str, int, VoiceChannel, StageChannel, ScheduledEventLocation] = MISSING,
start_time: datetime.datetime = MISSING,
end_time: datetime.datetime = MISSING,
cover: Optional[bytes] = MISSING,
privacy_level: ScheduledEventPrivacyLevel = ScheduledEventPrivacyLevel.guild_only,
reason: Optional[str] = None
) -> Optional[ScheduledEvent]:
"""|coro|
Expand Down Expand Up @@ -287,6 +291,8 @@ async def edit(
so there is no need to change this parameter.
reason: Optional[:class:`str`]
The reason to show in the audit log.
Optional[:class:`Asset`]
The cover image of the scheduled event.
Raises
-------
Expand Down Expand Up @@ -315,6 +321,12 @@ async def edit(
if privacy_level is not MISSING:
payload["privacy_level"] = int(privacy_level)

if cover is not MISSING:
if cover is None:
payload["image"]
else:
payload["image"] = utils._bytes_to_base64_data(cover)

if location is not MISSING:
if not isinstance(location, (ScheduledEventLocation, utils._MissingSentinel)):
location = ScheduledEventLocation(state=self._state, value=location)
Expand All @@ -328,7 +340,9 @@ async def edit(

location = location if location is not MISSING else self.location
if end_time is MISSING and location.type is ScheduledEventLocationType.external:
raise ValidationError("end_time needs to be passed if location type is external.")
end_time = self.end_time
if end_time is None:
raise ValidationError("end_time needs to be passed if location type is external.")

if start_time is not MISSING:
payload["scheduled_start_time"] = start_time.isoformat()
Expand Down

0 comments on commit 435c30d

Please sign in to comment.