mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
add: removeFromThread
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user