aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-04-18 20:54:16 -0400
committerRapptz <[email protected]>2019-04-18 22:31:54 -0400
commitf5c38c3559ba0ee39bee7204e324fb024189ec57 (patch)
treee47da0b3ad47213dcab77da093b4d733e98e6af1
parentAdd note about overriding Client.close vs Client.logout (diff)
downloaddiscord.py-f5c38c3559ba0ee39bee7204e324fb024189ec57.tar.xz
discord.py-f5c38c3559ba0ee39bee7204e324fb024189ec57.zip
Add abc.GuildChannel.clone to clone a channel with another name.
Fixes #2093
-rw-r--r--discord/abc.py40
-rw-r--r--discord/channel.py31
2 files changed, 71 insertions, 0 deletions
diff --git a/discord/abc.py b/discord/abc.py
index ec668f5c..b0ee61fe 100644
--- a/discord/abc.py
+++ b/discord/abc.py
@@ -603,6 +603,46 @@ class GuildChannel:
else:
raise InvalidArgument('Invalid overwrite type provided.')
+ async def _clone_impl(self, base_attrs, *, name=None, reason=None):
+ base_attrs['permission_overwrites'] = [
+ x._asdict() for x in self._overwrites
+ ]
+ base_attrs['parent_id'] = self.category_id
+ base_attrs['name'] = name or self.name
+ guild_id = self.guild.id
+ cls = self.__class__
+ data = await self._state.http.create_channel(guild_id, self._type, reason=reason, **base_attrs)
+ obj = cls(state=self._state, guild=self.guild, data=data)
+
+ # temporarily add it to the cache
+ self.guild._channels[obj.id] = obj
+ return obj
+
+ async def clone(self, *, name=None, reason=None):
+ """|coro|
+
+ Clones this channel. This creates a channel with the same properties
+ as this channel.
+
+ .. versionadded:: 1.1.0
+
+ Parameters
+ ------------
+ name: Optional[:class:`str`]
+ The name of the new channel. If not provided, defaults to this
+ channel name.
+ reason: Optional[:class:`str`]
+ The reason for cloning this channel. Shows up on the audit log.
+
+ Raises
+ -------
+ Forbidden
+ You do not have the proper permissions to create this channel.
+ HTTPException
+ Creating the channel failed.
+ """
+ raise NotImplementedError
+
async def create_invite(self, *, reason=None, **fields):
"""|coro|
diff --git a/discord/channel.py b/discord/channel.py
index 96f9e3c6..e3055f88 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -214,6 +214,15 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
"""
await self._edit(options, reason=reason)
+ async def clone(self, *, name=None, reason=None):
+ return await self._clone_impl({
+ 'topic': self.topic,
+ 'nsfw': self.nsfw,
+ 'rate_limit_per_user': self.slowmode_delay
+ }, name=name, reason=reason)
+
+ clone.__doc__ = discord.abc.GuildChannel.clone.__doc__
+
async def delete_messages(self, messages):
"""|coro|
@@ -526,6 +535,14 @@ class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
permissions_for.__doc__ = discord.abc.GuildChannel.permissions_for.__doc__
+ async def clone(self, *, name=None, reason=None):
+ return await self._clone_impl({
+ 'bitrate': self.bitrate,
+ 'user_limit': self.user_limit
+ }, name=name, reason=reason)
+
+ clone.__doc__ = discord.abc.GuildChannel.clone.__doc__
+
async def edit(self, *, reason=None, **options):
"""|coro|
@@ -629,6 +646,13 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
"""Checks if the category is NSFW."""
return self.nsfw
+ async def clone(self, *, name=None, reason=None):
+ return await self._clone_impl({
+ 'nsfw': self.nsfw
+ }, name=name, reason=reason)
+
+ clone.__doc__ = discord.abc.GuildChannel.clone.__doc__
+
async def edit(self, *, reason=None, **options):
"""|coro|
@@ -791,6 +815,13 @@ class StoreChannel(discord.abc.GuildChannel, Hashable):
"""Checks if the channel is NSFW."""
return self.nsfw
+ async def clone(self, *, name=None, reason=None):
+ return await self._clone_impl({
+ 'nsfw': self.nsfw
+ }, name=name, reason=reason)
+
+ clone.__doc__ = discord.abc.GuildChannel.clone.__doc__
+
async def edit(self, *, reason=None, **options):
"""|coro|