Add support for Guild.system_channel
This commit is contained in:
parent
b8c19954e4
commit
13c6a0a17a
@ -105,6 +105,7 @@ class AuditLogChanges:
|
||||
'inviter_id': ('inviter', _transform_inviter_id),
|
||||
'channel_id': ('channel', _transform_channel),
|
||||
'afk_channel_id': ('afk_channel', _transform_channel),
|
||||
'system_channel_id': ('system_channel', _transform_channel),
|
||||
'widget_channel_id': ('widget_channel', _transform_channel),
|
||||
'permission_overwrites': ('overwrites', _transform_overwrites),
|
||||
'splash_hash': ('splash', None),
|
||||
|
@ -122,7 +122,7 @@ class Guild(Hashable):
|
||||
'_default_role', 'roles', '_member_count', '_large',
|
||||
'owner_id', 'mfa_level', 'emojis', 'features',
|
||||
'verification_level', 'explicit_content_filter', 'splash',
|
||||
'_voice_states' )
|
||||
'_voice_states', '_system_channel_id', )
|
||||
|
||||
def __init__(self, *, data, state):
|
||||
self._channels = {}
|
||||
@ -214,6 +214,7 @@ class Guild(Hashable):
|
||||
self.emojis = tuple(map(lambda d: self._state.store_emoji(self, d), guild.get('emojis', [])))
|
||||
self.features = guild.get('features', [])
|
||||
self.splash = guild.get('splash')
|
||||
self._system_channel_id = guild.get('system_channel_id')
|
||||
|
||||
for mdata in guild.get('members', []):
|
||||
member = Member(data=mdata, guild=self, state=self._state)
|
||||
@ -308,6 +309,15 @@ class Guild(Hashable):
|
||||
"""Returns a :class:`abc.GuildChannel` with the given ID. If not found, returns None."""
|
||||
return self._channels.get(channel_id)
|
||||
|
||||
@property
|
||||
def system_channel(self):
|
||||
"""Optional[:class:`TextChannel`]: Returns the guild's channel used for system messages.
|
||||
|
||||
Currently this is only for new member joins. If no channel is set, then this returns ``None``.
|
||||
"""
|
||||
channel_id = self._system_channel_id
|
||||
return channel_id and self._channels.get(channel_id)
|
||||
|
||||
@property
|
||||
def members(self):
|
||||
"""List[:class:`Member`]: A list of members that belongs to this guild."""
|
||||
@ -627,6 +637,8 @@ class Guild(Hashable):
|
||||
The new verification level for the guild.
|
||||
vanity_code: str
|
||||
The new vanity code for the guild.
|
||||
system_channel: Optional[:class:`TextChannel`]
|
||||
The new channel that is used for the system channel. Could be ``None`` for no system channel.
|
||||
reason: Optional[str]
|
||||
The reason for editing this guild. Shows up on the audit log.
|
||||
|
||||
@ -683,6 +695,16 @@ class Guild(Hashable):
|
||||
else:
|
||||
fields['afk_channel_id'] = afk_channel.id
|
||||
|
||||
try:
|
||||
system_channel = fields.pop('system_channel')
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
if system_channel is None:
|
||||
fields['system_channel_id'] = system_channel
|
||||
else:
|
||||
fields['system_channel_id'] = system_channel.id
|
||||
|
||||
if 'owner' in fields:
|
||||
if self.owner != self.me:
|
||||
raise InvalidArgument('To transfer ownership you must be the owner of the guild.')
|
||||
|
@ -543,7 +543,8 @@ class HTTPClient:
|
||||
|
||||
def edit_guild(self, guild_id, *, reason=None, **fields):
|
||||
valid_keys = ('name', 'region', 'icon', 'afk_timeout', 'owner_id',
|
||||
'afk_channel_id', 'splash', 'verification_level')
|
||||
'afk_channel_id', 'splash', 'verification_level',
|
||||
'system_channel_id')
|
||||
|
||||
payload = {
|
||||
k: v for k, v in fields.items() if k in valid_keys
|
||||
|
10
docs/api.rst
10
docs/api.rst
@ -886,6 +886,7 @@ All enumerations are subclasses of `enum`_.
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
- :attr:`~AuditLogDiff.afk_channel`
|
||||
- :attr:`~AuditLogDiff.system_channel`
|
||||
- :attr:`~AuditLogDiff.afk_timeout`
|
||||
- :attr:`~AuditLogDiff.default_message_notifications`
|
||||
- :attr:`~AuditLogDiff.explicit_content_filter`
|
||||
@ -1491,6 +1492,15 @@ this goal, it must make use of a couple of data classes that aid in this goal.
|
||||
|
||||
See :attr:`Guild.afk_channel`.
|
||||
|
||||
.. attribute:: system_channel
|
||||
|
||||
Union[:class:`TextChannel`, :class:`Object`] – The guild's system channel.
|
||||
|
||||
If this could not be found, then it falls back to a :class:`Object`
|
||||
with the ID being set.
|
||||
|
||||
See :attr:`Guild.system_channel`.
|
||||
|
||||
.. attribute:: afk_timeout
|
||||
|
||||
*int* – The guild's AFK timeout. See :attr:`Guild.afk_timeout`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user