diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts index a1320611e..2de27e14e 100644 --- a/src/helpers/channels/threads/add_to_thread.ts +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -4,9 +4,9 @@ import { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; import { requireBotChannelPermissions } from "../../../util/permissions.ts"; -/** Adds the bot to a thread. When a user id is provided, it adds that user to the thread. User id requires the ability to send messages in the thread. Both requires the thread is not archived. +/** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. */ -export async function addToThread(threadId: bigint, userId?: bigint) { +export async function addToThread(threadId: bigint, userId: bigint) { const thread = await cacheHandlers.get("threads", threadId); if (thread) { if (thread.archived) { @@ -14,12 +14,10 @@ export async function addToThread(threadId: bigint, userId?: bigint) { } // If a user id is provided SEND_MESSAGES is required. - if (userId) { - const channel = await cacheHandlers.get("channels", thread.channelId); - // TODO: does MANAGE_THREADS override this???? - if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]); - } + const channel = await cacheHandlers.get("channels", thread.channelId); + // TODO: does MANAGE_THREADS override this???? + if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]); } - return await rest.runMethod("put", userId ? endpoints.THREAD_USER(threadId, userId) : endpoints.THREAD_ME(threadId)); + return await rest.runMethod("put", endpoints.THREAD_USER(threadId, userId)); } diff --git a/src/helpers/channels/threads/join_thread.ts b/src/helpers/channels/threads/join_thread.ts new file mode 100644 index 000000000..c3bf65e24 --- /dev/null +++ b/src/helpers/channels/threads/join_thread.ts @@ -0,0 +1,14 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { Errors } from "../../../types/discordeno/errors.ts"; +import { endpoints } from "../../../util/constants.ts"; + +/** Adds the bot to the thread. Cannot join an archived thread. */ +export async function joinThread(threadId: bigint) { + const thread = await cacheHandlers.get("threads", threadId); + if (thread?.archived) { + throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); + } + + return await rest.runMethod("put", endpoints.THREAD_ME(threadId)); +}