diff options
| author | Rapptz <[email protected]> | 2017-09-29 05:51:40 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-09-29 05:54:29 -0400 |
| commit | 711dfb83abae5486b70489e0151195ac4f316d52 (patch) | |
| tree | 44cd778bb8f8cbc65f50a31293d9bfe02fa5d7cb /discord/guild.py | |
| parent | Fix Guild.system_channel always returning None. (diff) | |
| download | discord.py-711dfb83abae5486b70489e0151195ac4f316d52.tar.xz discord.py-711dfb83abae5486b70489e0151195ac4f316d52.zip | |
Allow creating a channel with a category.
Diffstat (limited to 'discord/guild.py')
| -rw-r--r-- | discord/guild.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/discord/guild.py b/discord/guild.py index 9609dade..2e170143 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -515,7 +515,7 @@ class Guild(Hashable): return utils.find(pred, members) - def _create_channel(self, name, overwrites, channel_type, reason): + def _create_channel(self, name, overwrites, channel_type, category=None, reason=None): if overwrites is None: overwrites = {} elif not isinstance(overwrites, dict): @@ -540,10 +540,12 @@ class Guild(Hashable): perms.append(payload) - return self._state.http.create_channel(self.id, name, channel_type.value, permission_overwrites=perms, reason=reason) + parent_id = category.id if category else None + return self._state.http.create_channel(self.id, name, channel_type.value, parent_id=parent_id, + permission_overwrites=perms, reason=reason) @asyncio.coroutine - def create_text_channel(self, name, *, overwrites=None, reason=None): + def create_text_channel(self, name, *, overwrites=None, category=None, reason=None): """|coro| Creates a :class:`TextChannel` for the guild. @@ -583,6 +585,10 @@ class Guild(Hashable): A `dict` of target (either a role or a member) to :class:`PermissionOverwrite` to apply upon creation of a channel. Useful for creating secret channels. + category: Optional[:class:`CategoryChannel`] + The category to place the newly created channel under. + The permissions will be automatically synced to category if no + overwrites are provided. reason: Optional[str] The reason for creating this channel. Shows up on the audit log. @@ -600,7 +606,7 @@ class Guild(Hashable): :class:`TextChannel` The channel that was just created. """ - data = yield from self._create_channel(name, overwrites, ChannelType.text, reason=reason) + data = yield from self._create_channel(name, overwrites, ChannelType.text, category, reason=reason) channel = TextChannel(state=self._state, guild=self, data=data) # temporarily add to the cache @@ -608,12 +614,12 @@ class Guild(Hashable): return channel @asyncio.coroutine - def create_voice_channel(self, name, *, overwrites=None, reason=None): + def create_voice_channel(self, name, *, overwrites=None, category=None, reason=None): """|coro| Same as :meth:`create_text_channel` except makes a :class:`VoiceChannel` instead. """ - data = yield from self._create_channel(name, overwrites, ChannelType.voice, reason=reason) + data = yield from self._create_channel(name, overwrites, ChannelType.voice, category, reason=reason) channel = VoiceChannel(state=self._state, guild=self, data=data) # temporarily add to the cache @@ -625,6 +631,11 @@ class Guild(Hashable): """|coro| Same as :meth:`create_text_channel` except makes a :class:`CategoryChannel` instead. + + .. note:: + + The ``category`` parameter is not supported in this function since categories + cannot have categories. """ data = yield from self._create_channel(name, overwrites, ChannelType.category, reason=reason) channel = CategoryChannel(state=self._state, guild=self, data=data) |