From d0afe0859f30b82271b8c3b740172c2c0f0a7d42 Mon Sep 17 00:00:00 2001 From: Cam Date: Sun, 15 Jun 2025 04:11:18 +0100 Subject: [PATCH 1/2] Expose recurrence_rule --- discord/guild.py | 11 +++++++++++ discord/scheduled_event.py | 15 +++++++++++++++ discord/types/scheduled_event.py | 1 + 3 files changed, 27 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index 20a50d4e932f..8dd3a04c7764 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3201,6 +3201,7 @@ async def create_scheduled_event( end_time: datetime.datetime = ..., description: str = ..., image: bytes = ..., + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -3217,6 +3218,7 @@ async def create_scheduled_event( end_time: datetime.datetime = ..., description: str = ..., image: bytes = ..., + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -3232,6 +3234,7 @@ async def create_scheduled_event( end_time: datetime.datetime = ..., description: str = ..., image: bytes = ..., + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -3247,6 +3250,7 @@ async def create_scheduled_event( end_time: datetime.datetime = ..., description: str = ..., image: bytes = ..., + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -3263,6 +3267,7 @@ async def create_scheduled_event( end_time: datetime.datetime = MISSING, description: str = MISSING, image: bytes = MISSING, + recurrence_rule: str = MISSING, reason: Optional[str] = None, ) -> ScheduledEvent: r"""|coro| @@ -3308,6 +3313,9 @@ async def create_scheduled_event( The location of the scheduled event. Required if the ``entity_type`` is :attr:`EntityType.external`. + recurrence_rule: :class:`str` + The recurrence rule for the scheduled event in iCalendar format. + This determines how often the event repeats. reason: Optional[:class:`str`] The reason for creating this scheduled event. Shows up on the audit log. @@ -3377,6 +3385,9 @@ async def create_scheduled_event( image_as_str: str = utils._bytes_to_base64_data(image) payload['image'] = image_as_str + if recurrence_rule is not MISSING: + payload['recurrence_rule'] = recurrence_rule + if entity_type in (EntityType.stage_instance, EntityType.voice): if channel in (MISSING, None): raise TypeError('channel must be set when entity_type is voice or stage_instance') diff --git a/discord/scheduled_event.py b/discord/scheduled_event.py index f74ae67061e5..0a4b0ca6aa7e 100644 --- a/discord/scheduled_event.py +++ b/discord/scheduled_event.py @@ -104,6 +104,9 @@ class ScheduledEvent(Hashable): .. versionadded:: 2.2 location: Optional[:class:`str`] The location of the scheduled event. + recurrence_rule: Optional[:class:`str`] + The recurrence rule for the scheduled event in iCalendar format. + This determines how often the event repeats. """ __slots__ = ( @@ -125,6 +128,7 @@ class ScheduledEvent(Hashable): 'channel_id', 'creator_id', 'location', + 'recurrence_rule', ) def __init__(self, *, state: ConnectionState, data: GuildScheduledEventPayload) -> None: @@ -145,6 +149,7 @@ def _update(self, data: GuildScheduledEventPayload) -> None: self._cover_image: Optional[str] = data.get('image', None) self.user_count: int = data.get('user_count', 0) self.creator_id: Optional[int] = _get_as_snowflake(data, 'creator_id') + self.recurrence_rule: Optional[str] = data.get('recurrence_rule') creator = data.get('creator') self.creator: Optional[User] = self._state.store_user(creator) if creator else None @@ -343,6 +348,7 @@ async def edit( status: EventStatus = ..., image: bytes = ..., location: str, + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -359,6 +365,7 @@ async def edit( privacy_level: PrivacyLevel = ..., status: EventStatus = ..., image: bytes = ..., + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -375,6 +382,7 @@ async def edit( status: EventStatus = ..., image: bytes = ..., location: str, + recurrence_rule: str = ..., reason: Optional[str] = ..., ) -> ScheduledEvent: ... @@ -392,6 +400,7 @@ async def edit( status: EventStatus = MISSING, image: bytes = MISSING, location: str = MISSING, + recurrence_rule: str = MISSING, reason: Optional[str] = None, ) -> ScheduledEvent: r"""|coro| @@ -439,6 +448,9 @@ async def edit( The new location of the scheduled event. Required if the entity type is :attr:`EntityType.external`. + recurrence_rule: :class:`str` + The recurrence rule for the scheduled event in iCalendar format. + This determines how often the event repeats. reason: Optional[:class:`str`] The reason for editing the scheduled event. Shows up on the audit log. @@ -494,6 +506,9 @@ async def edit( image_as_str: Optional[str] = _bytes_to_base64_data(image) if image is not None else image payload['image'] = image_as_str + if recurrence_rule is not MISSING: + payload['recurrence_rule'] = recurrence_rule + entity_type = entity_type or getattr(channel, '_scheduled_event_entity_type', MISSING) if entity_type is MISSING: if channel and isinstance(channel, Object): diff --git a/discord/types/scheduled_event.py b/discord/types/scheduled_event.py index 52200367f134..e40dd97e392d 100644 --- a/discord/types/scheduled_event.py +++ b/discord/types/scheduled_event.py @@ -47,6 +47,7 @@ class _BaseGuildScheduledEvent(TypedDict): creator: NotRequired[User] user_count: NotRequired[int] image: NotRequired[Optional[str]] + recurrence_rule: NotRequired[Optional[str]] class _VoiceChannelScheduledEvent(_BaseGuildScheduledEvent): From 6be0f19ae53ed5342a5c245612eb262c2139e95c Mon Sep 17 00:00:00 2001 From: Cam Date: Sun, 15 Jun 2025 04:33:06 +0100 Subject: [PATCH 2/2] update docs --- docs/api.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api.rst b/docs/api.rst index e366f63bf312..c8cece285680 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1306,6 +1306,7 @@ Scheduled Events - The description is changed. - The status is changed. - The image is changed. + - The recurrence rule is changed. .. versionadded:: 2.0