Implement remaining HTTP endpoints on threads

I'm not sure if I missed any -- but this is the entire documented set
so far.
This commit is contained in:
Rapptz
2021-04-14 09:42:38 -04:00
parent 68c7c538f5
commit c1ce3b949f
5 changed files with 365 additions and 11 deletions

View File

@ -27,6 +27,7 @@ from __future__ import annotations
import time
import asyncio
from typing import Callable, Dict, List, Optional, TYPE_CHECKING, Union, overload
import datetime
import discord.abc
from .permissions import PermissionOverwrite, Permissions
@ -36,6 +37,8 @@ from . import utils
from .asset import Asset
from .errors import ClientException, NoMoreItems, InvalidArgument
from .stage_instance import StageInstance
from .threads import Thread
from .iterators import ArchivedThreadIterator
__all__ = (
'TextChannel',
@ -49,12 +52,12 @@ __all__ = (
)
if TYPE_CHECKING:
from .types.threads import ThreadArchiveDuration
from .role import Role
from .member import Member, VoiceState
from .abc import Snowflake
from .abc import Snowflake, SnowflakeTime
from .message import Message
from .webhook import Webhook
from .abc import SnowflakeTime
async def _single_delete_strategy(messages):
for m in messages:
@ -586,6 +589,80 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
from .message import PartialMessage
return PartialMessage(channel=self, id=message_id)
async def start_private_thread(self, *, name: str, auto_archive_duration: ThreadArchiveDuration = 1440) -> Thread:
"""|coro|
Starts a private thread in this text channel.
You must have :attr:`~discord.Permissions.send_messages` and
:attr:`~discord.Permissions.use_private_threads` in order to start a thread.
Parameters
-----------
name: :class:`str`
The name of the thread.
auto_archive_duration: :class:`int`
The duration in minutes before a thread is automatically archived for inactivity.
Defaults to ``1440`` or 24 hours.
Raises
-------
Forbidden
You do not have permissions to start a thread.
HTTPException
Starting the thread failed.
"""
data = await self._state.http.start_public_thread(
self.id,
name=name,
auto_archive_duration=auto_archive_duration,
type=ChannelType.private_thread.value,
)
return Thread(guild=self.guild, data=data)
async def archive_threads(
self,
*,
private: bool = True,
joined: bool = False,
limit: Optional[int] = 50,
before: Optional[Union[Snowflake, datetime.datetime]] = None,
) -> ArchivedThreadIterator:
"""Returns an :class:`~discord.AsyncIterator` that iterates over all archived threads in the guild.
You must have :attr:`~Permissions.read_message_history` to use this. If iterating over private threads
then :attr:`~Permissions.manage_messages` is also required.
Parameters
-----------
limit: Optional[:class:`bool`]
The number of threads to retrieve.
If ``None``, retrieves every archived thread in the channel. Note, however,
that this would make it a slow operation.
before: Optional[Union[:class:`abc.Snowflake`, :class:`datetime.datetime`]]
Retrieve archived channels before the given date or ID.
private: :class:`bool`
Whether to retrieve private archived threads.
joined: :class:`bool`
Whether to retrieve private archived threads that you've joined.
You cannot set ``joined`` to ``True`` and ``private`` to ``False``.
Raises
------
Forbidden
You do not have permissions to get archived threads.
HTTPException
The request to get the archived threads failed.
Yields
-------
:class:`Thread`
The archived threads.
"""
return ArchivedThreadIterator(self.id, self.guild, limit=limit, joined=joined, private=private, before=before)
class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
__slots__ = ('name', 'id', 'guild', 'bitrate', 'user_limit',
'_state', 'position', '_overwrites', 'category_id',