From 8c23b88dc51add10b99e34ad6ae5ccbc2b951a84 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 17:17:11 +0200 Subject: [PATCH] add: removeFromThread --- .../channels/threads/remove_from_thread.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/helpers/channels/threads/remove_from_thread.ts diff --git a/src/helpers/channels/threads/remove_from_thread.ts b/src/helpers/channels/threads/remove_from_thread.ts new file mode 100644 index 000000000..7cf250275 --- /dev/null +++ b/src/helpers/channels/threads/remove_from_thread.ts @@ -0,0 +1,29 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes } from "../../../types/channels/channel_types.ts"; +import { Errors } from "../../../types/misc/errors.ts"; +import { endpoints } from "../../../util/constants.ts"; + +/** Removes another user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. */ +export async function removeFromThread(channelId: string, userId?: string) { + // TODO(threads): perm check + const channel = await cacheHandlers.get("channels", channelId); + if (channel) { + if ( + ![ + ChannelTypes.GuildNewsThread, + ChannelTypes.GuildPivateThread, + ChannelTypes.GuildPublicThread, + ].includes(channel.type) + ) { + throw new Error(Errors.NOT_A_THREAD_CHANNEL); + } + } + + return await rest.runMethod( + "delete", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); +}