mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
6f280e7781
* refactor(types): move errors, file_content module to types/discordeno * refactor(types): move error & file_content module to discordeno/ * Update and fix import statements
34 lines
819 B
TypeScript
34 lines
819 B
TypeScript
import { botId } from "../../bot.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { Errors } from "../../types/discordeno/errors.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import {
|
|
isHigherPosition,
|
|
requireBotGuildPermissions,
|
|
} from "../../util/permissions.ts";
|
|
|
|
/** Add a role to the member */
|
|
export async function addRole(
|
|
guildId: bigint,
|
|
memberId: bigint,
|
|
roleId: bigint,
|
|
reason?: string,
|
|
) {
|
|
const isHigherRolePosition = await isHigherPosition(
|
|
guildId,
|
|
botId,
|
|
roleId,
|
|
);
|
|
if (!isHigherRolePosition) {
|
|
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
|
}
|
|
|
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
|
|
|
return await rest.runMethod<undefined>(
|
|
"put",
|
|
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
|
{ reason },
|
|
);
|
|
}
|