Skip to content

Commit

Permalink
Refactor Guild.afk_channel to use a property
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Jun 11, 2023
1 parent c5da0fe commit abfb3a1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ class Guild(Hashable):

__slots__ = (
'afk_timeout',
'afk_channel',
'name',
'id',
'unavailable',
Expand All @@ -298,6 +297,7 @@ class Guild(Hashable):
'vanity_url_code',
'widget_enabled',
'_widget_channel_id',
'_afk_channel_id',
'_members',
'_channels',
'_icon',
Expand Down Expand Up @@ -503,6 +503,7 @@ def _from_data(self, guild: GuildPayload) -> None:
self.premium_progress_bar_enabled: bool = guild.get('premium_progress_bar_enabled', False)
self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id')
self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250
self._afk_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'afk_channel_id')

if 'channels' in guild:
channels = guild['channels']
Expand All @@ -511,8 +512,6 @@ def _from_data(self, guild: GuildPayload) -> None:
if factory:
self._add_channel(factory(guild=self, data=c, state=self._state)) # type: ignore

self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, 'afk_channel_id')) # type: ignore

for obj in guild.get('voice_states', []):
self._update_voice_state(obj, int(obj['channel_id']))

Expand Down Expand Up @@ -761,6 +760,14 @@ def get_emoji(self, emoji_id: int, /) -> Optional[Emoji]:
return emoji
return None

@property
def afk_channel(self) -> Optional[VocalGuildChannel]:
"""Optional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]: The channel that denotes the AFK channel.
If no channel is set, then this returns ``None``.
"""
return self.get_channel(self._afk_channel_id) # type: ignore

@property
def system_channel(self) -> Optional[TextChannel]:
"""Optional[:class:`TextChannel`]: Returns the guild's channel used for system messages.
Expand Down Expand Up @@ -1875,8 +1882,6 @@ async def edit(
and ``public_updates_channel`` parameters are required.
.. versionadded:: 2.0
afk_channel: Optional[:class:`VoiceChannel`]
The new channel that is the AFK channel. Could be ``None`` for no AFK channel.
afk_timeout: :class:`int`
The number of seconds until someone is moved to the AFK channel.
owner: :class:`Member`
Expand Down

0 comments on commit abfb3a1

Please sign in to comment.