Browse Source

Add category parameter to abc.GuildChannel.clone

pull/9963/head
Andrin 6 months ago
committed by GitHub
parent
commit
a5f9350ff2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 19
      discord/abc.py
  2. 48
      discord/channel.py

19
discord/abc.py

@ -1005,11 +1005,15 @@ class GuildChannel:
base_attrs: Dict[str, Any],
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> Self:
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
if category is not None:
base_attrs['parent_id'] = category.id
guild_id = self.guild.id
cls = self.__class__
data = await self._state.http.create_channel(guild_id, self.type.value, reason=reason, **base_attrs)
@ -1019,7 +1023,13 @@ class GuildChannel:
self.guild._channels[obj.id] = obj # type: ignore # obj is a GuildChannel
return obj
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> Self:
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> Self:
"""|coro|
Clones this channel. This creates a channel with the same properties
@ -1029,11 +1039,18 @@ class GuildChannel:
.. versionadded:: 1.1
.. versionchanged:: 2.5
The ``category`` keyword-only parameter was added.
Parameters
------------
name: Optional[:class:`str`]
The name of the new channel. If not provided, defaults to this
channel name.
category: Optional[:class:`~discord.CategoryChannel`]
The category the new channel belongs to.
This parameter is ignored if cloning a category channel.
reason: Optional[:class:`str`]
The reason for cloning this channel. Shows up on the audit log.

48
discord/channel.py

@ -525,7 +525,13 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> TextChannel:
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> TextChannel:
return await self._clone_impl(
{
'topic': self.topic,
@ -535,6 +541,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
'default_thread_rate_limit_per_user': self.default_thread_slowmode_delay,
},
name=name,
category=category,
reason=reason,
)
@ -1499,6 +1506,18 @@ class VoiceChannel(VocalGuildChannel):
""":class:`ChannelType`: The channel's Discord type."""
return ChannelType.voice
@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> VoiceChannel:
return await self._clone_impl(
{'bitrate': self.bitrate, 'user_limit': self.user_limit}, name=name, category=category, reason=reason
)
@overload
async def edit(self) -> None:
...
@ -1769,6 +1788,16 @@ class StageChannel(VocalGuildChannel):
""":class:`ChannelType`: The channel's Discord type."""
return ChannelType.stage_voice
@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> StageChannel:
return await self._clone_impl({}, name=name, category=category, reason=reason)
@property
def instance(self) -> Optional[StageInstance]:
"""Optional[:class:`StageInstance`]: The running stage instance of the stage channel.
@ -2046,7 +2075,13 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
return self.nsfw
@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> CategoryChannel:
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel] = None,
reason: Optional[str] = None,
) -> CategoryChannel:
return await self._clone_impl({'nsfw': self.nsfw}, name=name, reason=reason)
@overload
@ -2563,7 +2598,13 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
return self._type == ChannelType.media.value
@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> ForumChannel:
async def clone(
self,
*,
name: Optional[str] = None,
category: Optional[CategoryChannel],
reason: Optional[str] = None,
) -> ForumChannel:
base = {
'topic': self.topic,
'rate_limit_per_user': self.slowmode_delay,
@ -2582,6 +2623,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
return await self._clone_impl(
base,
name=name,
category=category,
reason=reason,
)

Loading…
Cancel
Save