Add abc.GuildChannel.clone to clone a channel with another name.
Fixes #2093
This commit is contained in:
parent
ceb154718d
commit
f5c38c3559
@ -603,6 +603,46 @@ class GuildChannel:
|
|||||||
else:
|
else:
|
||||||
raise InvalidArgument('Invalid overwrite type provided.')
|
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):
|
async def create_invite(self, *, reason=None, **fields):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
@ -214,6 +214,15 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
"""
|
"""
|
||||||
await self._edit(options, reason=reason)
|
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):
|
async def delete_messages(self, messages):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -526,6 +535,14 @@ class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
|
|||||||
|
|
||||||
permissions_for.__doc__ = discord.abc.GuildChannel.permissions_for.__doc__
|
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):
|
async def edit(self, *, reason=None, **options):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -629,6 +646,13 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
"""Checks if the category is NSFW."""
|
"""Checks if the category is NSFW."""
|
||||||
return self.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):
|
async def edit(self, *, reason=None, **options):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -791,6 +815,13 @@ class StoreChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
"""Checks if the channel is NSFW."""
|
"""Checks if the channel is NSFW."""
|
||||||
return self.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):
|
async def edit(self, *, reason=None, **options):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user