From 4969beab19752c372a20ac98004cc5faf61c660b Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 9 Jun 2021 21:39:11 +0200 Subject: [PATCH] Update remove_from_thread.ts --- src/helpers/channels/threads/remove_from_thread.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/helpers/channels/threads/remove_from_thread.ts b/src/helpers/channels/threads/remove_from_thread.ts index fdd381022..021503a92 100644 --- a/src/helpers/channels/threads/remove_from_thread.ts +++ b/src/helpers/channels/threads/remove_from_thread.ts @@ -1,12 +1,13 @@ +import { botId } from "../../../bot.ts"; import { cacheHandlers } from "../../../cache.ts"; import { rest } from "../../../rest/rest.ts"; import { ChannelTypes } from "../../../types/channels/channel_types.ts"; import { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; +import { botHasChannelPermissions } from "../../../util/permissions.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: bigint, userId?: bigint) { - // TODO(threads): perm check const channel = await cacheHandlers.get("channels", channelId); if (channel) { if ( @@ -16,6 +17,9 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) { ) { throw new Error(Errors.NOT_A_THREAD_CHANNEL); } + + if (channel.ownerId !== botId && !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"]))) + throw new Error(Errors.HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS); } return await rest.runMethod(