mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
tyler is bae <3
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
14
src/helpers/channels/threads/join_thread.ts
Normal file
14
src/helpers/channels/threads/join_thread.ts
Normal file
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user