From 65fc6951bceaedc88997349c338d7e5b56b3ff5f Mon Sep 17 00:00:00 2001 From: "I. Ahmad" <54180221+nerdguyahmad@users.noreply.github.com> Date: Fri, 11 Mar 2022 14:09:56 +0500 Subject: [PATCH] Add support for stage instance's scheduled event --- discord/stage_instance.py | 16 +++++++++++++++- discord/types/channel.py | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/discord/stage_instance.py b/discord/stage_instance.py index 2a23dad74..fefc76e82 100644 --- a/discord/stage_instance.py +++ b/discord/stage_instance.py @@ -26,7 +26,7 @@ from __future__ import annotations from typing import Optional, TYPE_CHECKING -from .utils import MISSING, cached_slot_property +from .utils import MISSING, cached_slot_property, _get_as_snowflake from .mixins import Hashable from .enums import PrivacyLevel, try_enum @@ -41,6 +41,7 @@ if TYPE_CHECKING: from .state import ConnectionState from .channel import StageChannel from .guild import Guild + from .scheduled_event import ScheduledEvent class StageInstance(Hashable): @@ -76,6 +77,10 @@ class StageInstance(Hashable): The privacy level of the stage instance. discoverable_disabled: :class:`bool` Whether discoverability for the stage instance is disabled. + scheduled_event_id: Optional[:class:`int`] + The ID of scheduled event that belongs to the stage instance if any. + + .. versionadded:: 2.0 """ __slots__ = ( @@ -86,7 +91,9 @@ class StageInstance(Hashable): 'topic', 'privacy_level', 'discoverable_disabled', + 'scheduled_event_id', '_cs_channel', + '_cs_scheduled_event', ) def __init__(self, *, state: ConnectionState, guild: Guild, data: StageInstancePayload) -> None: @@ -100,6 +107,7 @@ class StageInstance(Hashable): self.topic: str = data['topic'] self.privacy_level: PrivacyLevel = try_enum(PrivacyLevel, data['privacy_level']) self.discoverable_disabled: bool = data.get('discoverable_disabled', False) + self.scheduled_event_id: Optional[int] = _get_as_snowflake(data, 'guild_scheduled_event_id') def __repr__(self) -> str: return f'' @@ -110,6 +118,12 @@ class StageInstance(Hashable): # the returned channel will always be a StageChannel or None return self._state.get_channel(self.channel_id) # type: ignore + @cached_slot_property('_cs_scheduled_event') + def scheduled_event(self) -> Optional[ScheduledEvent]: + """Optional[:class:`ScheduledEvent`]: The scheduled event that belongs to the stage instance.""" + # Guild.get_scheduled_event() expects an int, we are passing Optional[int] + return self.guild.get_scheduled_event(self.scheduled_event_id) # type: ignore + async def edit( self, *, diff --git a/discord/types/channel.py b/discord/types/channel.py index ecea39fa6..101378949 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -156,3 +156,4 @@ class StageInstance(TypedDict): topic: str privacy_level: PrivacyLevel discoverable_disabled: bool + guild_scheduled_event_id: Optional[int]