Update remove_from_thread.ts

This commit is contained in:
ITOH
2021-06-09 21:39:11 +02:00
parent bbc40a2db5
commit 4969beab19
@@ -1,12 +1,13 @@
import { botId } from "../../../bot.ts";
import { cacheHandlers } from "../../../cache.ts"; import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts"; import { rest } from "../../../rest/rest.ts";
import { ChannelTypes } from "../../../types/channels/channel_types.ts"; import { ChannelTypes } from "../../../types/channels/channel_types.ts";
import { Errors } from "../../../types/discordeno/errors.ts"; import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.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. */ /** 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) { export async function removeFromThread(channelId: bigint, userId?: bigint) {
// TODO(threads): perm check
const channel = await cacheHandlers.get("channels", channelId); const channel = await cacheHandlers.get("channels", channelId);
if (channel) { if (channel) {
if ( if (
@@ -16,6 +17,9 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) {
) { ) {
throw new Error(Errors.NOT_A_THREAD_CHANNEL); 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( return await rest.runMethod(