aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-08-17 18:13:18 -0400
committerRapptz <[email protected]>2017-08-17 18:14:52 -0400
commit13c6a0a17a1963d102f887e3be950c2e0dfdf36e (patch)
tree2761b078e826a27d0534fecc2728faeac1840de9
parentAdd default type for Game. (diff)
downloaddiscord.py-13c6a0a17a1963d102f887e3be950c2e0dfdf36e.tar.xz
discord.py-13c6a0a17a1963d102f887e3be950c2e0dfdf36e.zip
Add support for Guild.system_channel
-rw-r--r--discord/audit_logs.py1
-rw-r--r--discord/guild.py24
-rw-r--r--discord/http.py3
-rw-r--r--docs/api.rst10
4 files changed, 36 insertions, 2 deletions
diff --git a/discord/audit_logs.py b/discord/audit_logs.py
index 16c79aad..c33f8c32 100644
--- a/discord/audit_logs.py
+++ b/discord/audit_logs.py
@@ -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),
diff --git a/discord/guild.py b/discord/guild.py
index 5900623f..3f7b7270 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -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)
@@ -309,6 +310,15 @@ class Guild(Hashable):
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."""
return list(self._members.values())
@@ -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.')
diff --git a/discord/http.py b/discord/http.py
index b935cf99..57f99244 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -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
diff --git a/docs/api.rst b/docs/api.rst
index 24347d00..c0816af0 100644
--- a/docs/api.rst
+++ b/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`.