mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
34 lines
950 B
TypeScript
34 lines
950 B
TypeScript
import { botId } from "../../bot.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { Errors } from "../../types/misc/errors.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import {
|
|
highestRole,
|
|
requireBotGuildPermissions,
|
|
} from "../../util/permissions.ts";
|
|
|
|
/** Kick a member from the server */
|
|
export async function kick(guildId: string, memberId: string, reason?: string) {
|
|
const botsHighestRole = await highestRole(guildId, botId);
|
|
const membersHighestRole = await highestRole(guildId, memberId);
|
|
if (
|
|
botsHighestRole && membersHighestRole &&
|
|
botsHighestRole.position <= membersHighestRole.position
|
|
) {
|
|
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
|
}
|
|
|
|
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
|
|
|
const result = await rest.runMethod(
|
|
"delete",
|
|
endpoints.GUILD_MEMBER(guildId, memberId),
|
|
{ reason },
|
|
);
|
|
|
|
return result;
|
|
}
|
|
|
|
// aliases
|
|
export { kick as kickMember };
|