aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2018-09-14 22:52:39 -0400
committerRapptz <[email protected]>2018-09-14 22:55:29 -0400
commit0352c80a179d0ae0cd03b05725cfbb68d51e847f (patch)
tree9259ff6a71a2cd870db7347445a6067ebd9941ca
parentRemoved inaccurate note on emoji.py (diff)
downloaddiscord.py-0352c80a179d0ae0cd03b05725cfbb68d51e847f.tar.xz
discord.py-0352c80a179d0ae0cd03b05725cfbb68d51e847f.zip
Add support for Discord's slow mode.
Adds the following: * `slowmode_delay` for `TextChannel.edit` * `slowmode_delay` attribute for `TextChannel`
-rw-r--r--discord/abc.py5
-rw-r--r--discord/channel.py24
-rw-r--r--discord/http.py3
3 files changed, 24 insertions, 8 deletions
diff --git a/discord/abc.py b/discord/abc.py
index 365fcebf..0ca11452 100644
--- a/discord/abc.py
+++ b/discord/abc.py
@@ -231,6 +231,11 @@ class GuildChannel:
else:
parent_id = parent and parent.id
+ try:
+ options['rate_limit_per_user'] = options.pop('slowmode_delay')
+ except KeyError:
+ pass
+
lock_permissions = options.pop('sync_permissions', False)
try:
diff --git a/discord/channel.py b/discord/channel.py
index eb157ad9..32faf983 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -78,10 +78,15 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
position: :class:`int`
The position in the channel list. This is a number that starts at 0. e.g. the
top channel is position 0.
+ slowmode_delay: :class:`int`
+ The number of seconds a member must wait between sending messages
+ in this channel. A value of `0` denotes that it is disabled.
+ Bots and users with :attr:`~Permissions.manage_channels` or
+ :attr:`~Permissions.manage_messages` bypass slowmode.
"""
__slots__ = ('name', 'id', 'guild', 'topic', '_state', 'nsfw',
- 'category_id', 'position', '_overwrites')
+ 'category_id', 'position', 'slowmode_delay', '_overwrites')
def __init__(self, *, state, guild, data):
self._state = state
@@ -98,6 +103,8 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
self.topic = data.get('topic')
self.position = data['position']
self.nsfw = data.get('nsfw', False)
+ # Does this need coercion into `int`? No idea yet.
+ self.slowmode_delay = data.get('rate_limit_per_user', 0)
self._fill_overwrites(data)
async def _get_channel(self):
@@ -133,21 +140,24 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
Parameters
----------
- name: str
+ name: :class:`str`
The new channel name.
- topic: str
+ topic: :class:`str`
The new channel's topic.
- position: int
+ position: :class:`int`
The new channel's position.
- nsfw: bool
+ nsfw: :class:`bool`
To mark the channel as NSFW or not.
- sync_permissions: bool
+ sync_permissions: :class:`bool`
Whether to sync permissions with the channel's new or pre-existing
category. Defaults to ``False``.
category: Optional[:class:`CategoryChannel`]
The new category for this channel. Can be ``None`` to remove the
category.
- reason: Optional[str]
+ slowmode_delay: :class:`int`
+ Specifies the slowmode rate limit for user in this channel. A value of
+ `0` disables slowmode. The maximum value possible is `120`.
+ reason: Optional[:class:`str`]
The reason for editing this channel. Shows up on the audit log.
Raises
diff --git a/discord/http.py b/discord/http.py
index 2d5c67fb..6c2b548c 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -495,7 +495,8 @@ class HTTPClient:
def edit_channel(self, channel_id, *, reason=None, **options):
r = Route('PATCH', '/channels/{channel_id}', channel_id=channel_id)
- valid_keys = ('name', 'parent_id', 'topic', 'bitrate', 'nsfw', 'user_limit', 'position', 'permission_overwrites')
+ valid_keys = ('name', 'parent_id', 'topic', 'bitrate', 'nsfw',
+ 'user_limit', 'position', 'permission_overwrites', 'rate_limit_per_user')
payload = {
k: v for k, v in options.items() if k in valid_keys
}