aboutsummaryrefslogtreecommitdiff
path: root/discord/http.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-14 05:05:47 -0400
committerRapptz <[email protected]>2021-06-08 07:23:40 -0400
commit68c7c538f5a4e068664c3ee2f38f7343e229af1a (patch)
tree08a694d1f32e27283e08302ab1388d8579a1bb0c /discord/http.py
parent[types] Add support thread API typings (diff)
downloaddiscord.py-68c7c538f5a4e068664c3ee2f38f7343e229af1a.tar.xz
discord.py-68c7c538f5a4e068664c3ee2f38f7343e229af1a.zip
First pass at preliminary thread support
This is missing a lot of functionality right now, such as two gateway events and all the HTTP CRUD endpoints.
Diffstat (limited to 'discord/http.py')
-rw-r--r--discord/http.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/discord/http.py b/discord/http.py
index 3c4d8400..ee93d1a9 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -695,6 +695,8 @@ class HTTPClient:
'type',
'rtc_region',
'video_quality_mode',
+ 'archived',
+ 'auto_archive_duration',
)
payload = {k: v for k, v in options.items() if k in valid_keys}
return self.request(r, reason=reason, json=payload)
@@ -720,6 +722,7 @@ class HTTPClient:
'rate_limit_per_user',
'rtc_region',
'video_quality_mode',
+ 'auto_archive_duration',
)
payload.update({k: v for k, v in options.items() if k in valid_keys and v is not None})
@@ -728,6 +731,80 @@ class HTTPClient:
def delete_channel(self, channel_id, *, reason=None):
return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), reason=reason)
+ # Thread management
+
+ def start_public_thread(
+ self,
+ channel_id: int,
+ message_id: int,
+ *,
+ name: str,
+ auto_archive_duration: int,
+ type: int,
+ ):
+ payload = {
+ 'name': name,
+ 'auto_archive_duration': auto_archive_duration,
+ 'type': type,
+ }
+
+ route = Route(
+ 'POST', '/channels/{channel_id}/messages/{message_id}/threads', channel_id=channel_id, message_id=message_id
+ )
+ return self.request(route, json=payload)
+
+ def start_private_thread(
+ self,
+ channel_id: int,
+ *,
+ name: str,
+ auto_archive_duration: int,
+ type: int,
+ ):
+ payload = {
+ 'name': name,
+ 'auto_archive_duration': auto_archive_duration,
+ 'type': type,
+ }
+
+ route = Route('POST', '/channels/{channel_id}/threads', channel_id=channel_id)
+ return self.request(route, json=payload)
+
+ def join_thread(self, channel_id: int):
+ return self.request(Route('POST', '/channels/{channel_id}/thread-members/@me', channel_id=channel_id))
+
+ def add_user_to_thread(self, channel_id: int, user_id: int):
+ return self.request(
+ Route('POST', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
+ )
+
+ def leave_thread(self, channel_id: int):
+ return self.request(Route('DELETE', '/channels/{channel_id}/thread-members/@me', channel_id=channel_id))
+
+ def remove_user_from_thread(self, channel_id: int, user_id: int):
+ route = Route('DELETE', '/channels/{channel_id}/thread-members/{user_id}', channel_id=channel_id, user_id=user_id)
+ return self.request(route)
+
+ def get_archived_threads(self, channel_id: int, before=None, limit: int = 50, public: bool = True):
+ if public:
+ route = Route('GET', '/channels/{channel_id}/threads/archived/public', channel_id=channel_id)
+ else:
+ route = Route('GET', '/channels/{channel_id}/threads/archived/private', channel_id=channel_id)
+
+ params = {}
+ if before:
+ params['before'] = before
+ params['limit'] = limit
+ return self.request(route, params=params)
+
+ def get_joined_private_archived_threads(self, channel_id, before=None, limit: int = 50):
+ route = Route('GET', '/channels/{channel_id}/users/@me/threads/archived/private', channel_id=channel_id)
+ params = {}
+ if before:
+ params['before'] = before
+ params['limit'] = limit
+ return self.request(route, params=params)
+
# Webhook management
def create_webhook(self, channel_id, *, name, avatar=None, reason=None):