mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-10 03:47:57 +00:00
Add support for Discord's slow mode.
Adds the following: * `slowmode_delay` for `TextChannel.edit` * `slowmode_delay` attribute for `TextChannel`
This commit is contained in:
parent
21309c2d72
commit
0352c80a17
@ -231,6 +231,11 @@ class GuildChannel:
|
|||||||
else:
|
else:
|
||||||
parent_id = parent and parent.id
|
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)
|
lock_permissions = options.pop('sync_permissions', False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -78,10 +78,15 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
position: :class:`int`
|
position: :class:`int`
|
||||||
The position in the channel list. This is a number that starts at 0. e.g. the
|
The position in the channel list. This is a number that starts at 0. e.g. the
|
||||||
top channel is position 0.
|
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',
|
__slots__ = ('name', 'id', 'guild', 'topic', '_state', 'nsfw',
|
||||||
'category_id', 'position', '_overwrites')
|
'category_id', 'position', 'slowmode_delay', '_overwrites')
|
||||||
|
|
||||||
def __init__(self, *, state, guild, data):
|
def __init__(self, *, state, guild, data):
|
||||||
self._state = state
|
self._state = state
|
||||||
@ -98,6 +103,8 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
self.topic = data.get('topic')
|
self.topic = data.get('topic')
|
||||||
self.position = data['position']
|
self.position = data['position']
|
||||||
self.nsfw = data.get('nsfw', False)
|
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)
|
self._fill_overwrites(data)
|
||||||
|
|
||||||
async def _get_channel(self):
|
async def _get_channel(self):
|
||||||
@ -133,21 +140,24 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
name: str
|
name: :class:`str`
|
||||||
The new channel name.
|
The new channel name.
|
||||||
topic: str
|
topic: :class:`str`
|
||||||
The new channel's topic.
|
The new channel's topic.
|
||||||
position: int
|
position: :class:`int`
|
||||||
The new channel's position.
|
The new channel's position.
|
||||||
nsfw: bool
|
nsfw: :class:`bool`
|
||||||
To mark the channel as NSFW or not.
|
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
|
Whether to sync permissions with the channel's new or pre-existing
|
||||||
category. Defaults to ``False``.
|
category. Defaults to ``False``.
|
||||||
category: Optional[:class:`CategoryChannel`]
|
category: Optional[:class:`CategoryChannel`]
|
||||||
The new category for this channel. Can be ``None`` to remove the
|
The new category for this channel. Can be ``None`` to remove the
|
||||||
category.
|
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.
|
The reason for editing this channel. Shows up on the audit log.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
|
@ -495,7 +495,8 @@ class HTTPClient:
|
|||||||
|
|
||||||
def edit_channel(self, channel_id, *, reason=None, **options):
|
def edit_channel(self, channel_id, *, reason=None, **options):
|
||||||
r = Route('PATCH', '/channels/{channel_id}', channel_id=channel_id)
|
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 = {
|
payload = {
|
||||||
k: v for k, v in options.items() if k in valid_keys
|
k: v for k, v in options.items() if k in valid_keys
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user