Skip to content
Open
10 changes: 10 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"EntitlementOwnerType",
"IntegrationType",
"InteractionContextType",
"ScheduledEventRecurrenceFrequency",
)


Expand Down Expand Up @@ -1063,6 +1064,15 @@ class SubscriptionStatus(Enum):
inactive = 2


class ScheduledEventRecurrenceFrequency(Enum):
"""A scheduled event recurrence rule's frequency."""

yearly = 0
monthly = 1
weekly = 2
daily = 3


T = TypeVar("T")


Expand Down
28 changes: 22 additions & 6 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
from .onboarding import Onboarding
from .permissions import PermissionOverwrite
from .role import Role
from .scheduled_events import ScheduledEvent, ScheduledEventLocation
from .scheduled_events import (
ScheduledEvent,
ScheduledEventLocation,
ScheduledEventRecurrenceRule,
)
from .stage_instance import StageInstance
from .sticker import GuildSticker
from .threads import Thread, ThreadMember
Expand Down Expand Up @@ -3770,14 +3774,16 @@ async def create_scheduled_event(
*,
name: str,
description: str = MISSING,
start_time: datetime,
end_time: datetime = MISSING,
start_time: datetime.datetime,
end_time: datetime.datetime = MISSING,
location: str | int | VoiceChannel | StageChannel | ScheduledEventLocation,
privacy_level: ScheduledEventPrivacyLevel = ScheduledEventPrivacyLevel.guild_only,
reason: str | None = None,
image: bytes = MISSING,
) -> ScheduledEvent | None:
recurrence_rule: ScheduledEventRecurrenceRule | None = MISSING,
) -> ScheduledEvent:
"""|coro|

Creates a scheduled event.

Parameters
Expand All @@ -3799,7 +3805,10 @@ async def create_scheduled_event(
reason: Optional[:class:`str`]
The reason to show in the audit log.
image: Optional[:class:`bytes`]
The cover image of the scheduled event
The cover image of the scheduled event.
recurrence_rule: Optional[:class:`ScheduledEventRecurrenceRule`]
The recurrence rule this event will follow. If this is ``None`` then this is a
one-time event.

Returns
-------
Expand All @@ -3813,7 +3822,8 @@ async def create_scheduled_event(
HTTPException
The operation failed.
"""
payload: dict[str, str | int] = {

payload: dict[str, Any] = {
"name": name,
"scheduled_start_time": start_time.isoformat(),
"privacy_level": int(privacy_level),
Expand All @@ -3840,6 +3850,12 @@ async def create_scheduled_event(
if image is not MISSING:
payload["image"] = utils._bytes_to_base64_data(image)

if recurrence_rule is not MISSING:
if recurrence_rule is None:
payload["recurrence_rule"] = None
else:
payload["recurrence_rule"] = recurrence_rule._to_dict()

data = await self._state.http.create_scheduled_event(
guild_id=self.id, reason=reason, **payload
)
Expand Down
Loading