add: removeFromThread

This commit is contained in:
ITOH
2021-05-02 17:17:11 +02:00
parent 4faeab8bac
commit 8c23b88dc5
@@ -0,0 +1,29 @@
import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts";
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
import { Errors } from "../../../types/misc/errors.ts";
import { endpoints } from "../../../util/constants.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. */
export async function removeFromThread(channelId: string, userId?: string) {
// TODO(threads): perm check
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
if (
![
ChannelTypes.GuildNewsThread,
ChannelTypes.GuildPivateThread,
ChannelTypes.GuildPublicThread,
].includes(channel.type)
) {
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
}
}
return await rest.runMethod(
"delete",
userId
? endpoints.THREAD_USER(channelId, userId)
: endpoints.THREAD_ME(channelId),
);
}