mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Add support for stage instance's scheduled event
This commit is contained in:
parent
04535e4e1d
commit
65fc6951bc
@ -26,7 +26,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Optional, TYPE_CHECKING
|
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 .mixins import Hashable
|
||||||
from .enums import PrivacyLevel, try_enum
|
from .enums import PrivacyLevel, try_enum
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ if TYPE_CHECKING:
|
|||||||
from .state import ConnectionState
|
from .state import ConnectionState
|
||||||
from .channel import StageChannel
|
from .channel import StageChannel
|
||||||
from .guild import Guild
|
from .guild import Guild
|
||||||
|
from .scheduled_event import ScheduledEvent
|
||||||
|
|
||||||
|
|
||||||
class StageInstance(Hashable):
|
class StageInstance(Hashable):
|
||||||
@ -76,6 +77,10 @@ class StageInstance(Hashable):
|
|||||||
The privacy level of the stage instance.
|
The privacy level of the stage instance.
|
||||||
discoverable_disabled: :class:`bool`
|
discoverable_disabled: :class:`bool`
|
||||||
Whether discoverability for the stage instance is disabled.
|
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__ = (
|
__slots__ = (
|
||||||
@ -86,7 +91,9 @@ class StageInstance(Hashable):
|
|||||||
'topic',
|
'topic',
|
||||||
'privacy_level',
|
'privacy_level',
|
||||||
'discoverable_disabled',
|
'discoverable_disabled',
|
||||||
|
'scheduled_event_id',
|
||||||
'_cs_channel',
|
'_cs_channel',
|
||||||
|
'_cs_scheduled_event',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *, state: ConnectionState, guild: Guild, data: StageInstancePayload) -> None:
|
def __init__(self, *, state: ConnectionState, guild: Guild, data: StageInstancePayload) -> None:
|
||||||
@ -100,6 +107,7 @@ class StageInstance(Hashable):
|
|||||||
self.topic: str = data['topic']
|
self.topic: str = data['topic']
|
||||||
self.privacy_level: PrivacyLevel = try_enum(PrivacyLevel, data['privacy_level'])
|
self.privacy_level: PrivacyLevel = try_enum(PrivacyLevel, data['privacy_level'])
|
||||||
self.discoverable_disabled: bool = data.get('discoverable_disabled', False)
|
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:
|
def __repr__(self) -> str:
|
||||||
return f'<StageInstance id={self.id} guild={self.guild!r} channel_id={self.channel_id} topic={self.topic!r}>'
|
return f'<StageInstance id={self.id} guild={self.guild!r} channel_id={self.channel_id} topic={self.topic!r}>'
|
||||||
@ -110,6 +118,12 @@ class StageInstance(Hashable):
|
|||||||
# the returned channel will always be a StageChannel or None
|
# the returned channel will always be a StageChannel or None
|
||||||
return self._state.get_channel(self.channel_id) # type: ignore
|
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(
|
async def edit(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
|
@ -156,3 +156,4 @@ class StageInstance(TypedDict):
|
|||||||
topic: str
|
topic: str
|
||||||
privacy_level: PrivacyLevel
|
privacy_level: PrivacyLevel
|
||||||
discoverable_disabled: bool
|
discoverable_disabled: bool
|
||||||
|
guild_scheduled_event_id: Optional[int]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user