From bbc40a2db5b4f6c116ce18d08751b8c1337731bf Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 9 Jun 2021 21:39:08 +0200 Subject: [PATCH] Update get_thread_members.ts --- .../channels/threads/get_thread_members.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts index 7aa90d6db..cd91c9df3 100644 --- a/src/helpers/channels/threads/get_thread_members.ts +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -2,13 +2,17 @@ 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 { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts"; import { endpoints } from "../../../util/constants.ts"; +import { botHasChannelPermissions } from "../../../util/permissions.ts"; +import { ws } from "../../../ws/ws.ts"; -// TODO(threads): it seems like the documented return type is wrong /** Returns array of thread members objects that are members of the thread. */ export async function getThreadMembers(channelId: bigint) { - // TODO(threads): perm check - // TODO(threads): intents check + if (!(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) { + throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); + } + const channel = await cacheHandlers.get("channels", channelId); if (channel) { if ( @@ -18,7 +22,15 @@ export async function getThreadMembers(channelId: bigint) { ) { throw new Error(Errors.NOT_A_THREAD_CHANNEL); } + + if ( + channel.type === ChannelTypes.GuildPivateThread && + !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) && + !channel.member + ) + throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD); } + // TODO: v12 map the result to a nice collection return await rest.runMethod("get", endpoints.THREAD_MEMBERS(channelId)); }