mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
34 lines
968 B
TypeScript
34 lines
968 B
TypeScript
import { BotWithCache, ChannelTypes } from "../../../deps.ts";
|
|
import { requireBotChannelPermissions } from "../../permissions.ts";
|
|
|
|
export default function removeThreadMember(bot: BotWithCache) {
|
|
const removeThreadMemberOld = bot.helpers.removeThreadMember;
|
|
|
|
bot.helpers.removeThreadMember = async function (threadId, userId) {
|
|
if (userId === bot.id) {
|
|
throw new Error(
|
|
"To remove the bot from a thread, you must use bot.helpers.leaveThread()",
|
|
);
|
|
}
|
|
|
|
const channel = bot.channels.get(threadId);
|
|
|
|
if (channel) {
|
|
if (channel.archived) {
|
|
throw new Error(
|
|
"Cannot remove user from thread if thread is archived.",
|
|
);
|
|
}
|
|
|
|
if (
|
|
!(bot.id === channel.ownerId &&
|
|
channel.type === ChannelTypes.GuildPrivateThread)
|
|
) {
|
|
await requireBotChannelPermissions(bot, channel, ["MANAGE_MESSAGES"]);
|
|
}
|
|
}
|
|
|
|
return removeThreadMemberOld(threadId, userId);
|
|
};
|
|
}
|