diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts index fe0c2138d..3d9dab1db 100644 --- a/src/helpers/channels/threads/add_to_thread.ts +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -3,12 +3,13 @@ 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"; -//TODO(threads): this does not work rn -/** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event.Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. - * @param userId the user to add to the thread defaults to bot +import { botHasChannelPermissions, requireBotChannelPermissions } from "../../../util/permissions.ts"; + +/** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event. + * Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. + * @param userId the user to add to the thread defaults to bot */ export async function addToThread(channelId: bigint, userId?: bigint) { - // TODO(threads): perm check const channel = await cacheHandlers.get("channels", channelId); if (channel) { if ( @@ -18,6 +19,10 @@ export async function addToThread(channelId: bigint, userId?: bigint) { ) { throw new Error(Errors.NOT_A_THREAD_CHANNEL); } + + if (!(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) && !channel.member) { + throw new Error(Errors.HAVE_TO_BE_PART_OF_THE_THREAD_OR_A_THREAD_MODERATOR_TO_ADD_OTHERS_TO_A_THREAD); + } } return await rest.runMethod(